如果在MainView上添加了UIgestureRecogniser,如何在子视图中移动视图?

时间:2014-09-04 11:18:56

标签: ios uitextview uigesturerecognizer subviews

我有一个观点,添加了UITextView。我在主视图上添加了UIgestureRecognizer如果我移动主视图它会移动UItextView但是如果我从UItextView视图移动那么主视图就不会沿着它移动。

尝试: - 通过执行UITextView userInteractionEnabled禁用然后它可以正常工作但我应该在没有阻力时将其激活。

1 个答案:

答案 0 :(得分:0)

使用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;
}
}

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