关闭

手势操作 IOS

标签: UITapGestureRecogniz
532人阅读 评论(0) 收藏 举报
分类:

- (void)loadView

 

{

    

    self.view=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 300, 400)];

    self.view.backgroundColor=[UIColor redColor];

    

    imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];

    imageView.image=[UIImage imageNamed:@"h1.jpg"];

    imageView.tag=100;

    imageView.userInteractionEnabled=YES;

    

    [self.view addSubview:imageView];

    [imageView release];

    

    

    UITapGestureRecognizer* tapges=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];

    tapges.numberOfTapsRequired=1;

    [imageView addGestureRecognizer:tapges];

    [tapges release];

    

    //长按

    UILongPressGestureRecognizer*pressges=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longImageView:)];

    [imageView addGestureRecognizer:pressges];

    [pressges release];

    //捏合

    UIPinchGestureRecognizer*pinchGRer=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchImageView:)];

    [imageView addGestureRecognizer:pinchGRer];

    [pinchGRer release];

    //旋转

    

    UIRotationGestureRecognizer*rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationImageView:)];

    [imageView addGestureRecognizer:rotation];

    [rotation release];

    

    //清扫

    UISwipeGestureRecognizer*swipeGRer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeImageView:)];

    

    [imageView addGestureRecognizer:swipeGRer];

    [swipeGRer release];

    

    //拖拽

    UIPanGestureRecognizer*panGRer=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panImageView:)];

    [imageView addGestureRecognizer:panGRer];

    [panGRer release];

}

-(void)tapImageView:(UITapGestureRecognizer*)sender

{


}

-(void)longImageView:(UILongPressGestureRecognizer*)sender

{


}

-(void)pinchImageView:(UIPinchGestureRecognizer* )sender

{

    //imageView

}


-(void)rotationImageView:(UIRotationGestureRecognizer*)sender


{

    imageView.transform=CGAffineTransformMakeRotation(sender.rotation);

}

-(void)swipeImageView:(UISwipeGestureRecognizer*)sender

{

    NSString*imageName=[NSString stringWithFormat:@"hi.jpeg",arc4random()%20+1];

}

-(void) pantapImageView:(UIPanGestureRecognizer*)sender

{

    sPoint=[sender locationInView:imageView];

    if (sender.state==UIGestureRecognizerStateBegan) {

        sPoint=[sender locationInView:imageView];

    }

    CGPoint current=[sender locationInView:imageView];

    float disx=current.x-sPoint.x;

    float disy=current.y-sPoint.y;

    

    imageView.center=CGPointMake(imageView.center.x+disx, imageView.center.y+disy);

    

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:52439次
    • 积分:1108
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:3篇
    • 译文:0篇
    • 评论:10条
    最新评论