【问题标题】:How move a view along subview if UIgestureRecogniser added on MainView?如果在 MainView 上添加 UIgestureRecogniser,如何沿子视图移动视图?
【发布时间】:2014-09-04 11:18:55
【问题描述】:

我对此添加了UITextView 的看法。如果我移动主视图,我在主视图上添加了一个UIgestureRecognizer,它会随着UItextView 移动,但如果我从 UItextView 视图移动,那么主视图不会沿着它移动。

尝试过:- 通过执行 UITextView userInteractionEnabled 禁用它就可以了,但我应该在没有阻力的情况下激活它。

【问题讨论】:

    标签: ios uitextview uigesturerecognizer subviews


    【解决方案1】:

    使用PanGestureReconizer 和句柄

    -(void)handleResizePanGesture:(UIPanGestureRecognizer*)p {
    
    if (p.state ==UIGestureRecognizerStateBegan) {
    
        touchStart = [p translationInView:self];
        touchStart = CGPointMake(touchStart.x - self.bounds.size.width,
                                 touchStart.y - self.bounds.size.height);
    
    }
    if (p.state == UIGestureRecognizerStateChanged) {
    
    
            touchPoint = [p translationInView:self];
            self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
                                    touchPoint.x - touchStart.x, touchPoint.y - touchStart.y);
            UITextView *textV = (UITextView*)[self viewWithTag:100];
            textV.frame = CGRectMake(self.bounds.origin.x+HotCornerHeight/2, self.bounds.origin.y+HotCornerHeight/2,
                                     touchPoint.x - touchStart.x-HotCornerHeight, touchPoint.y - touchStart.y-HotCornerHeight);
    
            UIButton *resButton = (UIButton*)[self viewWithTag:102];
            resButton.frame = CGRectMake(self.bounds.size.width-resizeButton,self.bounds.size.height-resizeButton, resizeButton,resizeButton);
    
    }
    
    if (p.state ==UIGestureRecognizerStateEnded || p.state ==UIGestureRecognizerStateEnded) {
        return;
    }
    }
    

    '

    希望这会为其他人节省一些时间。

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多