菜鸟教程小白 发表于 2022-12-11 20:34:20

ios - 如何使用 UIPanGestureRecognizer move 2 个或更多 UIImageViews


                                            <p><p>在解释如何使用 UIPanGestureRecognizermoveUIImageView 时,这个网站非常有帮助,但我有一个程序需要 move (即平移)多个 UIImageView,而且我一生都可以'找不到如何做到这一点的示例。</p>

<p>我知道将 UIPanGestureRecognizer 分配给 UIView,但我无法在 UIView 内平移任何 UIImageView,我只知道代码只能平移一个 UIImageView 与 UIView,如下面的代码所示。</p >

<p>这是我使用的代码。</p>

<pre><code>- (void)viewDidLoad {
UIPanGestureRecognizer *panRecognizer = [initWithTarget:self action:@selector(move:)];
;
;
;

; }


-(void)move:(id)sender {
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:_canvas];

if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
    _firstX = .x;
    _firstY = .y;
}

translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
; }
</code></pre>

<p>我可以平移一个名为 photoImage 的 UIImageView,但知道平移多个 UIImageView 的代码是什么样的。</p>

<p>提前感谢您的帮助。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您应该将手势识别器添加到所有图像而不是 _canvas。
并将这些 View 的 userInteractionEnabled 设置为 YES</p>

<pre><code>;
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何使用 UIPanGestureRecognizermove2 个或更多 UIImageViews,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8212792/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8212792/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何使用 UIPanGestureRecognizer move 2 个或更多 UIImageViews