每次单击imageview时旋转图像

时间:2013-04-27 16:16:10

标签: objective-c cocoa-touch cocoa

我有一些图像视图,每次触摸时都应旋转90°。这是我的代码:

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

这只是在第一次触摸时旋转它,当它再次录音时如何让它旋转90°?

1 个答案:

答案 0 :(得分:0)

首先应获取lineImage的当前变换,然后将其旋转90度。以下代码将解决您的问题

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

并确保您已启用了图像视图的uesr交互,

  [imageView1 setUserInteractionEnabled:YES];
  [imageView2 setUserInteractionEnabled:YES];