xcode - 移动手势
Posted 与格律上
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于xcode - 移动手势的主要内容,如果未能解决你的问题,请参考以下文章