UISlider控件的使用解析

骆嘉石
2023-12-01

上传一段通过UISlider控件来控制动画速度的代码

@implementation RootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

   self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [superviewDidLoad];

    //imageName:方法是从bundle()中找照片

    UIImageView *imageView1=[[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"453_36388_882073.jpg"]];

    imageView1.center=CGPointMake(160,320);

    [self.viewaddSubview:imageView1];

    imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(15,40,289, 220)];

    [self.viewaddSubview:imageView];

    NSMutableArray*images=[[NSMutableArrayalloc]initWithCapacity:7];

   for (int i=0; i<7; i++) {   //一共设置了7张图片

        NSString *imageName=[NSStringstringWithFormat:@"u=4207553503,3962206909&fm=21&gp=0.jpg%d(被拖移).tiff",i+1];//图片名称这里可以改成你想要的一切图片,但是请注意这些图片的关联性.这里注意%d的指代.

       UIImage* image=[UIImageimageNamed:imageName];


        [imagesaddObject:image];

    }

    imageView.animationImages=images;//imageView设置为全局变量;

    //imageView指定一组用于做动画的图片

    imageView.animationDuration=0.1;//动画的总时长(一组动画显示下来的总时间)

    imageView.animationRepeatCount=3;//显示图片循环次数.

    [self.viewaddSubview:imageView];

    [imageViewstartAnimating];

    

    UISlider*slider=[[UISlideralloc]initWithFrame:CGRectMake(20,240,280, 30)];

    slider.maximumValue=5;

    slider.minimumValue=0.1;

    [slider addTarget:selfaction:@selector(changeSpeed:)forControlEvents:UIControlEventAllEvents];

     NSLog(@"++++++++++++++++++%f",imageView.animationDuration);

    [self.viewaddSubview:slider];

    

    


// Do any additional setup after loading the view.

    

}

-(void)changeSpeed:(UISlider*)slider{


   imageView.animationDuration=slider.value;

   [imageViewstartAnimating];

    NSLog(@"---------------%f",imageView.animationDuration);//打印输出下时长的值,便于观察变化


}

 类似资料: