图片连续播放、UISegmentedControl、UISlider、UISwitch、UIStepper
MainViewController.h
#import<UIKit/UIKit.h>@interfaceMainViewController:UIViewController@property(nonatomic,retain)UISwitch*leftSwitch;@end
MainViewController.m
#import"MainViewController.h"@interfaceMainViewController()@end@implementationMainViewController@synthesizeleftSwitch;-(id)initWithNibName:(NSString*)nibNameOrNilbundle:(NSBundle*)nibBundleOrNil{self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];if(self){//Custominitialization}returnself;}-(void)viewDidLoad{[superviewDidLoad];//Doanyadditionalsetupafterloadingtheview.//首先创建一个UIImageViewUIImageView*p_w_picpathView=[[UIImageViewalloc]initWithFrame:CGRectMake(20,170,280,300)];p_w_picpathView.backgroundColor=[UIColorbrownColor];//p_w_picpathView.alpha=0.3;[self.viewaddSubview:p_w_picpathView];[p_w_picpathViewrelease];//给ImageView设置要播放的图片数组//1.创建一个空的可变的数组NSMutableArray*p_w_picpaths=[NSMutableArrayarray];for(inti=0;i<22;i++){//2.利用for循环产生UIImage对象NSString*name=[NSStringstringWithFormat:@"Zombie%d.tiff",i];//产生图片对象UIImage*p_w_picpath=[UIImagep_w_picpathNamed:name];//添加到数组中[p_w_picpathsaddObject: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_picpathViewstartAnimating];[p_w_picpathViewstopAnimating];//UISegmentedControlUISegmentedControl*segmeng=[[UISegmentedControlalloc]initWithItems:@[@"僵尸",@"丧尸",@"吸血鬼"]];segmeng.frame=CGRectMake(40,35,240,30);segmeng.backgroundColor=[UIColormagentaColor];segmeng.alpha=0.3;segmeng.layer.cornerRadius=7;segmeng.tintColor=[UIColoryellowColor];//改变颜色//绑定一个触发事件(方法)[segmengaddTarget:selfaction:@selector(segmengAction:)forControlEvents:UIControlEventValueChanged];[self.viewaddSubview:segmeng];[segmengrelease];//UISlider的使用UISlider*slider=[[UISlideralloc]initWithFrame:CGRectMake(40,70,240,30)];[slideraddTarget:selfaction:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];//改变slider的最大值slider.maximumValue=10;//最小值slider.minimumValue=0.1;//slider.maximumValueImage[self.viewaddSubview:slider];[sliderrelease];//UISwitch的使用leftSwitch=[[UISwitchalloc]initWithFrame:CGRectMake(40,100,30,20)];[leftSwitchaddTarget:selfaction:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];[self.viewaddSubview:leftSwitch];//UIStepper的使用UIStepper*stepper=[[UIStepperalloc]initWithFrame:CGRectMake(160,100,40,20)];stepper.backgroundColor=[UIColorblueColor];stepper.alpha=0.3;//Setactiontargetandactionforaparticularvaluechangedevent[stepperaddTarget:selfaction:@selector(stepper:)forControlEvents:UIControlEventValueChanged];//Setminandmax[steppersetMinimumValue:0.1];[steppersetMaximumValue:10];[steppersetWraps:YES];//ifYES,valuewrapsfrommin<->max.default=NO//[steppersetContinuous:NO];[steppersetStepValue:0.5];//设置每次跳动的值[self.viewaddSubview:stepper];}-(void)stepper:(UIStepper*)stepper{UIImageView*p_w_picpathView=(UIImageView*)[self.viewviewWithTag:1000];p_w_picpathView.animationDuration=stepper.value;[p_w_picpathViewstartAnimating];NSLog(@"%f",stepper.value);}-(void)switchAction:(id)sender{UIImageView*p_w_picpathView=(UIImageView*)[self.viewviewWithTag:1000];UISwitch*mySwitch=(UISwitch*)sender;BOOLsetting=mySwitch.isOn;if(setting){[p_w_picpathViewstartAnimating];NSLog(@"YES");}else{[p_w_picpathViewstopAnimating];NSLog(@"NO");}[leftSwitchsetOn:settinganimated:YES];//[rightSwitchsetOn:settinganimated:YES];}-(void)sliderAction:(UISlider*)slider{//改变僵尸的移动速度UIImageView*p_w_picpathView=(UIImageView*)[self.viewviewWithTag:1000];//利用slider的值改变p_w_picpathView播放一次需要的时间p_w_picpathView.animationDuration=slider.value;[p_w_picpathViewstartAnimating];//在重新播放NSLog(@"%f",slider.value);}-(void)segmengAction:(UISegmentedControl*)seg{NSLog(@"%d",seg.selectedSegmentIndex);if(0==seg.selectedSegmentIndex){NSLog(@"僵尸");}elseif(1==seg.selectedSegmentIndex){NSLog(@"丧尸");}elseif(2==seg.selectedSegmentIndex){NSLog(@"吸血鬼");}}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];//Disposeofanyresourcesthatcanberecreated.}/*#pragmamark-Navigation//Inastoryboard-basedapplication,youwilloftenwanttodoalittlepreparationbeforenavigation-(void)prepareForSegue:(UIStoryboardSegue*)seguesender:(id)sender{//Getthenewviewcontrollerusing[seguedestinationViewController].//Passtheselectedobjecttothenewviewcontroller.}*/@end
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。