iphone - 在 ScrollView 中旋转缩放 ImageView?
<p><p>我有一个 <code>UIScrollView</code> 有一个缩放 <code>UIImageView</code>,即它实现:</p>
<pre><code>- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
</code></pre>
<p>我正在尝试将 <code>UIRotationGestureRecognizer</code> 添加到此 <code>imageView</code> 中,我这样做如下:</p>
<pre><code>_rotationGestureRecognizer = [ initWithTarget:self action:@selector(rotate:)];
;
-(void)rotate:(id)sender
{
UIRotationGestureRecognizer *rotationGestureRecognizer = [(UIRotationGestureRecognizer*)sender retain];
if(rotationGestureRecognizer.state == UIGestureRecognizerStateEnded)
{
self.lastRotation = 0.0;
return;
}
CGFloat rotation = 0.0 - (self.lastRotation - rotationGestureRecognizer.rotation);
rotationGestureRecognizer.view.transform = CGAffineTransformRotate(rotationGestureRecognizer.view.transform, rotation);
self.lastRotation = rotationGestureRecognizer.rotation;
;
}
</code></pre>
<p>我只是想知道,是否有可能做到这一点?似乎 <code>UIScrollView</code> 阻止了对我的 <code>UIImageView</code> 的触摸,因为没有发生任何事情。 Apple 是否建议不要在 <code>UIScrollView</code> 中使用缩放 View 来执行此操作?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>以下代码正在运行。将手势添加到 scrollView 而不是 imageView。</p>
<pre><code> UIRotationGestureRecognizer* _rotationGestureRecognizer = [ initWithTarget:self action:@selector(rotate:)];
;
</code></pre>
<p><strong>Swift 5 版本:</strong></p>
<pre><code>let rotationGestureRecognizer = UIRotationGestureRecognizer(target: self, action: #selector(self.rotate(_:)))
scrollView.addGestureRecognizer(rotationGestureRecognizer)
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 在 ScrollView 中旋转缩放 ImageView?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14167646/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14167646/
</a>
</p>
页:
[1]