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

拖动实现图片移动效果

时间:2017-05-19 12:55:36      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:tom   post   tar   动效   sla   div   art   height   意图   

   拖动实现图片移动效果


先写一个手势,注意图片的 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];


}


拖动实现图片移动效果

标签:tom   post   tar   动效   sla   div   art   height   意图   

原文地址:http://www.cnblogs.com/clnchanpin/p/6877759.html

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