xcode - 移动手势
#import "ViewController.h" @interface ViewController () /** 创建一个UIView */ @property(nonatomic , weak) UIView * gestureView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建一个uiview UIView * tempView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 100, 100)]; //设置背景颜色 tempView.backgroundColor = [UIColor orangeColor]; self.gestureView=tempView; //创建手势 UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGes:)]; //绑定手势 [self.gestureView addGestureRecognizer:pan]; [self.view addSubview:self.gestureView]; } - (void)panGes:(UIPanGestureRecognizer *)pan{ CGPoint tranP = [pan translationInView:self.gestureView]; self.gestureView.transform = CGAffineTransformTranslate(self.gestureView.transform, tranP.x, tranP.y); [pan setTranslation:CGPointZero inView:self.gestureView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end