iOS各种手势与UISlider的运用

#import "RootViewController.h"


@interface RootViewController ()

@property(nonatomic,retain)UIImageView *aview;


@end


@implementation RootViewController



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

{

   self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    return self;

}

- (void)viewDidLoad

{

    [superviewDidLoad];

    // Do any additional setup after loading the view.

   

 _aview = [[UIImageViewalloc] initWithFrame:CGRectMake(60,100, 200, 200)];

    _aview.backgroundColor = [UIColorgrayColor];

    [self.viewaddSubview:_aview];



 //旋转

    _aview.userInteractionEnabled =YES;//打开交互旋转

   

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(handelRotationGesture:)];

    [_aviewaddGestureRecognizer:rotation];//添加手势识别器

    [rotationrelease];

    

   //捏合

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pingchAction:)];

    [_aviewaddGestureRecognizer:pinch];

    [pinchrelease];

    

   //平移

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panAction:)];

    [_aviewaddGestureRecognizer:pan];

    [panrelease];

   //轻扫

    

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeColor:)];

    [_aviewaddGestureRecognizer:swipe];

    [swiperelease];

    //- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment;

    

    //添加响应方式

    [_asegmentaddTarget:selfaction:@selector(handelSegementControlAction:)forControlEvents:(UIControlEventValueChanged)];

    

    _asegment.momentary =YES;//点完以后会起来,按钮(瞬间选中离开)默认为NO

    [_asegmentsetEnabled:NOforSegmentAtIndex:3];//不能使用的按钮(灰色)

  

    

    //滑块在设置的范围内,提供数据,滑块停留在某个位置,即得到某个数值.


   UISlider *slider = [[UISlideralloc]initWithFrame:CGRectMake(60,310,200, 30)];

    [self.viewaddSubview:slider];

    [sliderrelease];

    slider.minimumValue =0.05;

    slider.maximumValue =2;

    slider.minimumTrackTintColor = [UIColorredColor];

    

    

    [slider addTarget:selfaction:@selector(handelSliderAction:)forControlEvents:(UIControlEventValueChanged)];

    

    //播放视图动画

    NSMutableArray * array = [NSMutableArrayarrayWithCapacity:40];//image对象

    

   for (int i =1;i<8 ;i++ ) {

        //图片名字 ,图片名字有误,image = nil;                                 2250_3650903_179fb89ae279fae%d(被拖移).tiff

        NSString *name = [NSStringstringWithFormat:@"2250_3650903_179fb89ae279fae%d(被拖移).tiff",i];

        //创建image

       UIImage *image = [UIImageimageNamed:name];

       //添加到数组中

        

        [arrayaddObject:image];

        

      //UIAlertView

    }

    _aview.animationImages = array;

    //[_aview startAnimating];

    _aview.animationDuration =0.5;

    //_aview.animationRepeatCount = 2;//2秒播放完就没了

    [_aviewstartAnimating];

    //_aview.animationDuration =5;

    //[_aview stopAnimating];


    

}


//平移

- (void)panAction:(UIPanGestureRecognizer *)pan

{

   CGPoint panpoint = [pantranslationInView:pan.view];

    NSLog(@"panpoint = %@",NSStringFromCGPoint(panpoint));


    pan.view.transform =CGAffineTransformMakeTranslation(panpoint.x, panpoint.y);


}

//捏合

- (void)pingchAction:(UIPinchGestureRecognizer *)pinch

{

    pinch.view.transform =CGAffineTransformMakeScale(pinch.scale, pinch.scale);


}


//轻扫


- (void)changeColor:(UISwipeGestureRecognizer *)swipe

{


    _aview.backgroundColor = [[UIColoralloc]initWithRed:arc4random()%256/255.0green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];

}


//旋转


- (void)handelRotationGesture:(UIRotationGestureRecognizer *)rotationGesture

{   //修改仿射矩阵

//    _aview.transform = CGAffineTransformRotate(_aview.transform, rotationGesture.rotation);

    rotationGesture.view.transform =CGAffineTransformMakeRotation(rotationGesture.rotation);

   // rotationGesture.rotation = 0;//旋转角度重新置为零

   NSLog(@"rotation = %f",rotationGesture.rotation);//旋转角度

}

//[Dubai]slider相应的方法

- (void)handelSliderAction:(UISlider *)slider

{


    NSLog(@"%s",__FUNCTION__);

    //滑块当前的值设置为动画时间

    _aview.animationDuration = slider.value;

    [_aviewstartAnimating];

    

}


如图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值