美文网首页
手势 复习

手势 复习

作者: 雷仔 | 来源:发表于2016-02-24 00:26 被阅读16次

    //在下面写出控件的基本属性

    - (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    //建立一个图片视图(想要通过手势操作这个图片)

    UIImageView *imaView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 64, 300, 500)];

    imaView.image = [UIImage imageNamed:@"S3.jpg"];

    imaView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:imaView];

    [imaView release];

    imaView.userInteractionEnabled = YES;

    //轻拍手势 最常用到的手势

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick:)];

    [imaView addGestureRecognizer:tap];

    [tap release];

    //需要触碰几次

    tap.numberOfTapsRequired = 3;

    //需要几个手指触摸

    tap.numberOfTouchesRequired = 2;

    //其次重要的手势 长按

    UILongPressGestureRecognizer *lp = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpclick:)];

    [imaView addGestureRecognizer:lp];

    [lp release];

    lp.numberOfTouchesRequired = 2;

    lp.minimumPressDuration = 2;

    }

    //每个手势都需要用到其中的方法

    //长按的方法

    - (void)lpclick: (UILongPressGestureRecognizer *)lp

    {

    //如果这个状态是长按的情况下 输出"长按"

    if (lp.state == UIGestureRecognizerStateBegan) {

    NSLog(@"长按");

    }

    }

    //轻拍的方法

    - (void)tapclick: (UITapGestureRecognizer *)tap

    {

    NSLog(@"轻拍");

    }

    //以上两个手势最为常见

    相关文章

      网友评论

          本文标题:手势 复习

          本文链接:https://www.haomeiwen.com/subject/wlfikttx.html