您好,登錄后才能下訂單哦!
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. //首先創建一個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設置要播放的圖片數組 //1.創建一個空的可變的數組 NSMutableArray *p_w_picpaths = [NSMutableArray array]; for (int i = 0; i < 22; i++) { //2.利用for循環產生UIImage對象 NSString *name = [NSString stringWithFormat:@"Zombie%d.tiff", i]; //產生圖片對象 UIImage *p_w_picpath = [UIImage p_w_picpathNamed:name]; //添加到數組中 [p_w_picpaths addObject:p_w_picpath]; } p_w_picpathView.tag = 1000; //給p_w_picpathView賦值 p_w_picpathView.animationImages = p_w_picpaths; //播放完全部圖片的時間 p_w_picpathView.animationDuration = 0.1; //重復播放的次數 p_w_picpathView.animationRepeatCount = 0; //如果設置為0,則為不限次 //啟動動畫播放圖片 // [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];//改變顏色 // 綁定一個觸發事件(方法) [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];//設置每次跳動的值 [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 { //改變僵尸的移動速度 UIImageView *p_w_picpathView = (UIImageView *)[self.view viewWithTag:1000]; //利用slider的值改變p_w_picpathView播放一次需要的時間 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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。