码迷,mamicode.com
首页 > 移动开发 > 详细

给UIView加上移动的手势

时间:2014-11-15 11:15:40      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   sp   div   on   

 

背景图:

bubuko.com,布布扣

 

代码:

 

- (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加上移动的手势

标签:style   blog   http   io   color   ar   sp   div   on   

原文地址:http://www.cnblogs.com/yang-guang-girl/p/4098994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!