手勢、手勢在視圖間的傳遞

1、手勢

(1) Tap、LongPress...事件

2、手勢在視圖間的傳遞

Class SubView:UIView {get

}it

SubView *subView = [SubView new];io

(1)視圖上添加手勢event

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annoViewAction:)];class

[subView addGestureRecognizer:tapGesture];select

(2)手勢中獲取當前視圖im

SubView *subview = (SubView*)gesture.view;next

(3)touchBegan中獲取操做視圖touch

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    

    CGPoint point = [[touches anyObject] locationInView:self.view];

    point = [self.subView1.layer convertPoint:point fromLayer:self.view.layer];

    if ([self.subView1.layer containsPoint:point]) {

       //處理點擊到這個view中要執行的事件

        

        return;

    }

}

3、獲取View所在的Controller

id responder = self.nextResponder;

        while (![responder isKindOfClass: [UIViewController class]] && ![responder isKindOfClass: [UIWindow class]])

        {

            responder = [responder nextResponder];

        }

        if ([responder isKindOfClass: [UIViewController class]])

        {

            // responder就是view所在的控制器

            // do something

            [responder dismissViewControllerAnimated:YES completion:nil];

        }

 4、轉化座標系統

4.1轉換子視圖座標至目標視圖的座標系

- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;

相關文章
相關標籤/搜索