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

xcode - 移动手势

时间:2016-06-26 22:25:25      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

#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 - 移动手势

标签:

原文地址:http://www.cnblogs.com/fleas/p/5618601.html

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