溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

圖片連續(xù)播放、UISegmentedControl、UISlider、UISwitch、UIStepper

發(fā)布時(shí)間:2020-07-03 07:23:01 來源:網(wǎng)絡(luò) 閱讀:620 作者:Im劉亞芳 欄目:開發(fā)技術(shù)

MainViewController.h

#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
@property(nonatomic,retain)UISwitch*leftSwitch;
@end

MainViewController.m

#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
@synthesize leftSwitch;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //首先創(chuàng)建一個(gè)UIImageView
    UIImageView *p_w_picpathView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 170, 280, 300)];
    p_w_picpathView.backgroundColor = [UIColor brownColor];
//    p_w_picpathView.alpha = 0.3;
    [self.view addSubview:p_w_picpathView];
    [p_w_picpathView release];
    
    //給ImageView設(shè)置要播放的圖片數(shù)組
    //1.創(chuàng)建一個(gè)空的可變的數(shù)組
    NSMutableArray *p_w_picpaths = [NSMutableArray array];
    for (int i = 0; i < 22; i++) {
        //2.利用for循環(huán)產(chǎn)生UIImage對象
        NSString *name = [NSString stringWithFormat:@"Zombie%d.tiff", i];
        //產(chǎn)生圖片對象
        UIImage *p_w_picpath = [UIImage p_w_picpathNamed:name];
        //添加到數(shù)組中
        [p_w_picpaths addObject:p_w_picpath];
    }
    
    p_w_picpathView.tag = 1000;
    //給p_w_picpathView賦值
    p_w_picpathView.animationImages = p_w_picpaths;
    //播放完全部圖片的時(shí)間
    p_w_picpathView.animationDuration = 0.1;
    //重復(fù)播放的次數(shù)
    p_w_picpathView.animationRepeatCount = 0;  //如果設(shè)置為0,則為不限次
    //啟動(dòng)動(dòng)畫播放圖片
//    [p_w_picpathView startAnimating];
    [p_w_picpathView stopAnimating];
    
    
    
    
    //UISegmentedControl
    UISegmentedControl *segmeng = [[UISegmentedControl alloc] initWithItems:@[@"僵尸",@"喪尸",@"吸血鬼"]];
    segmeng.frame = CGRectMake(40, 35, 240, 30);
    segmeng.backgroundColor = [UIColor magentaColor];
    segmeng.alpha = 0.3;
    segmeng.layer.cornerRadius = 7;
    segmeng.tintColor = [UIColor yellowColor];//改變顏色
    // 綁定一個(gè)觸發(fā)事件(方法)
    [segmeng addTarget:self action:@selector(segmengAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmeng];
    [segmeng release];
    
    //UISlider的使用
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(40, 70, 240, 30)];
    
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    //改變slider的最大值
    slider.maximumValue = 10;
    //最小值
    slider.minimumValue = 0.1;
    //slider.maximumValueImage
    [self.view addSubview:slider];
    [slider release];
    
    //UISwitch的使用
    leftSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(40, 100, 30, 20)];
    [leftSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:leftSwitch];
    
    
    //UIStepper 的使用
    
    UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(160  , 100, 40, 20)];
    stepper.backgroundColor = [UIColor blueColor];
    stepper.alpha = 0.3;
    // Set action target and action for a particular value changed event
    [stepper addTarget:self action:@selector(stepper:) forControlEvents:UIControlEventValueChanged];
    // Set min and max
    [stepper setMinimumValue:0.1];
    [stepper setMaximumValue:10];
    [stepper setWraps:YES];   //if YES, value wraps from min <-> max. default = NO
//    [stepper setContinuous:NO];
    [stepper setStepValue:0.5];//設(shè)置每次跳動(dòng)的值
    [self.view addSubview:stepper];
    
    
    
}
- (void)stepper:(UIStepper *)stepper
{
    UIImageView *p_w_picpathView = (UIImageView *)[self.view viewWithTag:1000];
    p_w_picpathView.animationDuration = stepper.value;
    [p_w_picpathView startAnimating];
    NSLog(@"%f", stepper.value);
}
- (void)switchAction:(id)sender
{
    UIImageView *p_w_picpathView = (UIImageView *)[self.view viewWithTag:1000];
    UISwitch *mySwitch = (UISwitch *)sender;
    BOOL setting = mySwitch.isOn;
    if (setting) {
        [p_w_picpathView startAnimating];
        NSLog(@"YES");
    }else{
        [p_w_picpathView stopAnimating];
        NSLog(@"NO");
    }
    [leftSwitch setOn:setting animated:YES];
//    [rightSwitch setOn:setting animated:YES];
}
- (void)sliderAction:(UISlider *)slider
{
    //改變僵尸的移動(dòng)速度
    UIImageView *p_w_picpathView = (UIImageView *)[self.view viewWithTag:1000];
    //利用slider的值改變p_w_picpathView播放一次需要的時(shí)間
    p_w_picpathView.animationDuration = slider.value;
    [p_w_picpathView startAnimating];  //在重新播放
    NSLog(@"%f",slider.value);
}
- (void)segmengAction:(UISegmentedControl *)seg
{
    NSLog(@"%d",seg.selectedSegmentIndex);
    if (0 == seg.selectedSegmentIndex) {
        NSLog(@"僵尸");
    }else if (1 == seg.selectedSegmentIndex){
        NSLog(@"喪尸");
    }else if(2 == seg.selectedSegmentIndex){
        NSLog(@"吸血鬼");
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
@end



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI