UIControl(UIUISegmentedControl,UIStepper,UISlider滑块,播放本地MP3,毛玻璃效果,动画的连续播放)

UIStepper


#import <AVFoundation/AVFoundation.h>(1).引用处理音频的系统 文件

@property(nonatomic,retain)UIStepper *stepper;

@property(nonatomic,retain)AVAudioPlayer *play;


创建个UIStepper

self.stepper = [[UIStepperalloc]initWithFrame:CGRectMake(100,100, 100,100)];

[self.viewaddSubview:self.stepper];

[self.stepperrelease];


最大值,最小值

self.stepper.maximumValue =100;

self.stepper.minimumValue =0;


点击一次变化 2

self.stepper.stepValue =2;

[self.stepperaddTarget:selfaction:@selector(stepAction:)forControlEvents:UIControlEventValueChanged];


---------------------------------------------------------------------------------------------------------------------------------------------------------

实现播放本地MP3音乐的功能

(2).找到文件所对应的路径(盛夏光年)

NSString *path = [[NSBundle mainBundle] pathForResource:@"盛夏光年" ofType:@"mp3"];

  

(3).创建

self.play = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];


(4).播放

[self.play play];

[self.play release];

    

(5).UIStepper调整当前的音量就是用self.stepper调用方法


调整当前的音量的方法

-(void)stepAction:(UIStepper *)stepper

{

   NSLog(@"%g", stepper.value);

   self.play.volume(音量)self.stepper.value相关联(因为两者的类型都相同全都是double类型)

   self.play.volume  =self.stepper.value;

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

让图片拥有毛玻璃效果

(1).添加一个图片.毛玻璃

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"580.jpeg"]];

imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);

[self.view addSubview:imageView];

[imageView release];

 

(2).先创建一个效果,指定效果.毛玻璃

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];


创建一个毛玻璃视图.毛玻璃

UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:effect];


让毛玻璃效果的范围和图片的尺寸相等

effectView.frame = imageView.frame;

[imageView addSubview:effectView];

---------------------------------------------------------------------------------------------------------------------------------------------------------

实现动画的连续播放(播放gif)

(1).创建两个属性.gif

@property(nonatomic,retain)UIImageView *tomcatImageView;

@property(nonatomic,retain)NSMutableArray *picArr;


(2).创建.gif

self.tomcatImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

[self.view addSubview:self.tomcatImageView];

[self.tomcatImageView release];


(3).对容器使用之前,一定要对容器进行初始化.gif

self.picArr = [NSMutableArray array];


(4).照片一共有0 - 39对图片的名称进行拼接.gif

for (NSInteger i = 0; i < 40; i++) {

        

(5)拼接图片的名称.gif

NSLog(@"%02ld", i);//输出两位数不够两位用0补位(目的是与图片的编号一致)

        

NSString *picName = [NSString stringWithFormat:@"eat_%02ld.jpg", i];//

NSLog(@"%@", picName);

             

(6).根据图片名称找到对应的图片.gif

UIImage *image = [UIImage imageNamed:picName];

       

(7).把图片添加到数组中.gif

[self.picArr addObject:image];

}

  

(8).把数组中的图片给tomcatImageView.gif

self.tomcatImageView.animationImages = self.picArr;


(9).设置动画播放时间.gif

self.tomcatImageView.animationDuration = 4;

    

(10).播放次数.gif

self.tomcatImageView.animationRepeatCount = 10;

  

(11).动画开始.gif

[self.tomcatImageView startAnimating];

---------------------------------------------------------------------------------------------------------------------------------------------------------


UISlider(滑块手机锁之类的)

(1).创建属性.滑块

@property(nonatomic,retain)UISlider *slider;

创建

self.slider = [[UISlider alloc]initWithFrame:CGRectMake(100, 300, 200, 10)];

self.slider.backgroundColor = [UIColor yellowColor];

[self.view addSubview:self.slider];

[self.slider release];

 

最大值,最小值

self.slider.minimumValue = 0.5;

self.slider.maximumValue = 5;

   

[self.slider addTarget:self action:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];注意类型是改变数值


用滑块来调整动画的播放时长

-(void)sliderAction:(UISlider *)slider

{

    NSLog(@"%g", slider.value);

    self.tomcatImageView.animationDuration = slider.value;

    [self.tomcatImageViewstartAnimating];

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

@property(nonatomic,retain)UISegmentedControl *segmented;


UISegmentedControl

    

self.segmented = [[UISegmentedControl alloc]initWithItems:[NSMutableArray arrayWithObjects:@"0",@"1",@"2", @"3", nil]];

self.segmented.frame = CGRectMake(20, 400, 320, 80);

self.segmented.backgroundColor = [UIColor greenColor];

[self.view addSubview:self.segmented];


设置初始时默认的位置是2

self.segmented.selectedSegmentIndex = 2;


[self.segmented release];

 [self.segmented addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];


通过点击知道 按的是哪个按钮 按钮默认是从0开始的

-(void)segAction:(UISegmentedControl *)seg

{

    NSLog(@"%ld", seg.selectedSegmentIndex);

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值