手势、手势在视图间的传递

一、手势

(1) Tap、LongPress...

二、手势在视图间的传递

Class SubView:UIView {

}

SubView *subView = [SubView new];

(1)视图上添加手势

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

[subView addGestureRecognizer:tapGesture];

(2)手势中获取当前视图

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

(3)touchBegan中获取操作视图

- (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;

    }

}

三、获取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.1转换子视图坐标至目标视图的坐标系

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

posted @ 2018-10-06 10:00  Wind678  阅读(296)  评论(0编辑  收藏  举报