//
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 给imageView添加手势
self.imageView.userInteractionEnabled = YES;
// 创建手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.imageView addGestureRecognizer:pan];
}
- (void)pan:(UIPanGestureRecognizer *)recognizer
{
// 获取手势的移动,也是相对于最开始的位置
CGPoint point = [recognizer translationInView:self.imageView];
self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, point.x, point.y);
// 复位
[recognizer setTranslation:CGPointZero inView:self.imageView];
}
@end
手势识别器(UIGestureRecognizer)- UIPanGestureRecognizer(拖拽)
最新推荐文章于 2018-02-06 15:21:28 发布