码迷,mamicode.com
首页 > 移动开发 > 详细

拖动实现图片移动效果

时间:2015-07-01 18:24:32      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:拖动   图片移动效果   拖动实现图片移动效果   拖动动画   ios   

   拖动实现图片移动效果


先写一个手势,注意图片的 userInteractionEnabled设置为yes

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

    UIImage *image = [UIImage imageNamed:@"r.jpg"];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 40, 80, 80)];

    imageView.image = image;

    imageView.userInteractionEnabled = YES;

    [self addSubview:imageView];

    [imageView addGestureRecognizer:pan];

    

   

}

拖动的方法,最后一句是关键代码


- (void)pan:(UIPanGestureRecognizer *)gesture

{

    CGPoint point = [gesture translationInView:self];

    gesture.view.center = CGPointMake(gesture.view.center.x + point.x, gesture.view.center.y + point.y);

    [gesture setTranslation:CGPointMake(0, 0) inView:self];


}


版权声明:本文为博主原创文章,未经博主允许不得转载。

拖动实现图片移动效果

标签:拖动   图片移动效果   拖动实现图片移动效果   拖动动画   ios   

原文地址:http://blog.csdn.net/lu_ca/article/details/46711681

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!