首页 > 代码库 > 给UIView加上移动的手势

给UIView加上移动的手势

 

背景图:

 

代码:

 

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.            //红色的背景图    UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];    parentView.backgroundColor=[UIColor redColor];    [self.view addSubview:parentView];        [parentView setUserInteractionEnabled:YES];            //移动的手势    UIPanGestureRecognizer *panRcognize=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];    panRcognize.delegate=self;    [panRcognize setEnabled:YES];    [panRcognize delaysTouchesEnded];    [panRcognize cancelsTouchesInView];        [parentView addGestureRecognizer:panRcognize];}#pragma UIGestureRecognizer Handles- (void)handlePan:(UIPanGestureRecognizer *)recognizer {        NSLog(@"--移动的手势-----");    }

 

给UIView加上移动的手势