0

我有 2 个图像视图,我希望它们在单击时旋转。这是我的代码:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizerMethod:)];

然后在tapRecognizerMethod

- (void)tapRecognizerMethod:(UITapGestureRecognizer *)tapRecognize
{
    if (tapRecognize == tapRecognizer) // tapRecognizer is the first imageviews recognizer
    {
        if (tapRecognize.state == what should go here? 
        {
            //do something
        }
    }
}

应该追求tapRecognize ==什么?

4

3 回答 3

0
- (void)handleTap:(UITapGestureRecognizer *)tapRecognize
    {
        if (tapRecognize == tapRecognizer)
        {
            CGAffineTransform transform = CGAffineTransformRotate(lineImage.transform, 90);
            [lineImage setTransform:transform];
        }
    }

并确保您已启用 imageviews 的 uesr 交互,

  [imageView1 setUserInteractionEnabled:YES];
  [imageView2 setUserInteractionEnabled:YES];
于 2013-04-27T17:30:31.473 回答
0
- (void)tapRecognizerMethod:(UITapGestureRecognizer *)tapRecognize{
  if (tapRecognize == tapRecognizer){
     if (tapRecognize.state == UIGestureRecognizerStateEnded){
            UIImageView *imgView = (UIImageView*)[tapRecognize view];
            //Now need to rotate the image
     }
  }
}

看看以下链接: 旋转图像

于 2013-04-27T15:36:07.340 回答
0

如果你真的需要翻转旋转,你最好选择下面的滑动手势。

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
                                           initWithTarget:self
                                           action:@selector(handleSwipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[imageView addGestureRecognizer:swipeLeft];
[swipeLeft release];

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
                                            initWithTarget:self
                                            action:@selector(handleSwipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[imageView addGestureRecognizer:swipeRight];
[swipeRight release];

在处理程序方法上,您为单独的左右翻转提供动画

if(isActiveFlipLeft)
{
[UIView transitionWithView:imageSnap
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    imageSnap.backgroundColor = [UIColor colorWithRed:187.0/225.0 green:187.0/225.0 blue:187.0/225.0 alpha:1.0];
                    imageSnap.image = image;                        
} completion:NULL];}
else if (isActiveFlipRight)
{
[UIView transitionWithView:imageSnap
                          duration:1.0f
                           options:UIViewAnimationOptionTransitionFlipFromRight
                        animations:^{
                            imageSnap.backgroundColor = [UIColor colorWithRed:187.0/225.0 green:187.0/225.0 blue:187.0/225.0 alpha:1.0];
                            imageSnap.image = image;                                
} completion:NULL];}

下面的代码只是一个简单的点击手势。你会接到handleSingleTap的电话:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];

[singleTap setNumberOfTapsRequired:1];

[imageView addGestureRecognizer:singleTap];

[singleTap release];

手势处理程序

- (void)handleSwipeLeft:(UIGestureRecognizer *)gestureRecognizer;
- (void)handleSwipeRight:(UIGestureRecognizer *)gestureRecognizer;
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer;

如果您需要真正的旋转,您可以使用

imageview.transform = CGAffineTransformMakeRotation( 270.0/180*M_PI );

像在你的手势处理程序中的东西

于 2013-04-27T17:48:44.003 回答