首页 > 移动平台 > 详细

iOS 手势

时间:2015-04-21 13:08:37      阅读:209      评论:0      收藏:0      [点我收藏+]

-(void)viewDidLoad

{

    [super viewDidLoad];

    imageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 120, 120)];

    imageView.image=[UIImage imageNamed:@"2.jpg"];

    [self.view addSubview:imageView];

    [imageView release];

    imageView.userInteractionEnabled=YES;

    //-----添加手势——点击

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];//tap :点击|gesture:手势|Recognizer:承认者/响应者

    [imageView addGestureRecognizer:tap];

    tap.numberOfTapsRequired=2;//需要点击几次? required:需求

    tap.numberOfTouchesRequired=2;//几个触点啊? touches:触点

    [tap release];

    //-----添加手势——平移

    UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];//pan:

    [imageView addGestureRecognizer:pan];

    [pan release];

    //------添加手势——旋转

    UIRotationGestureRecognizer * rotation=[[UIRotationGestureRecognizer alloc] initWithTarget:selfaction:@selector(rotation:)];//Rotation:旋转

    [imageView addGestureRecognizer:rotation];

    //------添加手势——收缩

    UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

    [imageView addGestureRecognizer:pinch];

    [pinch release];

    [rotation release];

}

 //收缩实现——//bounds:界限 |scale :比例 友情提示,bounds 中心点不改变X,Y轴的距离,只改变长宽。

-(void)pinch:(UIPinchGestureRecognizer *)pinch

{

    imageView.bounds=CGRectMake(0, 0, imageView.bounds.size.width*pinch.scale,imageView.bounds.size.height*pinch.scale);//bounds:界限 |scale :比例 友情提示,bounds 中心点不改变X,Y轴的距离,只改变长宽。

    pinch.scale=1.0;

}

-(void)pan:(UIPanGestureRecognizer *)pan

{

    CGPoint point=[pan translationInView:self.view];// translation :平移 获取相对坐标原点的坐标

    NSLog(@"%f,%f",point.x,point.y);

    imageView.center=CGPointMake(imageView.center.x+point.ximageView.center.y+point.y);

    [pan setTranslation:CGPointZero inView:self.view];//设置坐标原点位上次的坐标

}

   //旋转

-(void)rotation:(UIRotationGestureRecognizer *)rotation

{

    imageView.transform=CGAffineTransformMakeRotation(finRotation+rotation.rotation);//transform :弧度改变 |affine:仿射  弧度改变

    if(rotation.state==UIGestureRecognizerStateEnded)//监听响应者的状态,判断是否结束

    {

        finRotation+=rotation.rotation;//弧度修改

    }

    NSLog(@"元方你怎么看?%f",rotation.rotation);

}

-(void)tap:(UITapGestureRecognizer *)tap

{

    NSLog(@"tap");

}

iOS 手势

原文:http://blog.csdn.net/sun_winter/article/details/45167741

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!