gpt4 book ai didi

iphone - UIImageview 上的 UIRotationGestureRecognizer

转载 作者:可可西里 更新时间:2023-11-01 04:19:20 24 4
gpt4 key购买 nike

如何在 iOS SDK 中用两个手指触摸旋转 UIImageView..我知道这很简单但是因为我是这项技术的新手所以无法理解...

如何使用 UIRotationGestureRecognizer 来实现这个...

请帮我解决这个问题...

谢谢。

最佳答案

在 View 加载或 ImageView 创建函数上编写此代码:m_ctrlImgVwShowImage - 你的 ImageView

UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease];
[rotationRecognizer setDelegate:self];
[m_ctrlImgVwShowImage addGestureRecognizer:rotationRecognizer];

//lastRotation is a cgfloat member variable

-(void)rotate:(id)sender {
if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
_lastRotation = 0.0;
return;
}

CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

CGAffineTransform currentTransform = m_ctrlImgVwShowImage.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

[m_ctrlImgVwShowImage setTransform:newTransform];

_lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}

关于iphone - UIImageview 上的 UIRotationGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com