iOS拖动手势的使用

来源:互联网 发布:按键精灵免费网络验证 编辑:程序博客网 时间:2024/05/01 09:33
#import "ViewController.h"@interface ViewController ()<UIGestureRecognizerDelegate>{    UIImageView *imgView ;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];       UIImage *img =[ UIImage imageNamed:@"q.jpg"];    imgView =[[UIImageView alloc]initWithImage:img];        imgView.userInteractionEnabled=YES;    [imgView sizeToFit];    imgView.center=self.view.center;    [self.view addSubview:imgView];    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];    pan.delegate=self;    [imgView addGestureRecognizer:pan];}-(void)pan:(UIPanGestureRecognizer*)pan{     NSLog(@"有%ld根手指同时触摸",[pan numberOfTouches]);    CGPoint point = [pan translationInView:[pan view]];    pan.view.transform=CGAffineTransformTranslate(pan.view.transform, point.x, point.y);    [pan setTranslation:CGPointMake(0, 0) inView:[pan view]];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

0 0
原创粉丝点击