美文网首页
iOS常用知识

iOS常用知识

作者: L小杰 | 来源:发表于2017-08-23 16:33 被阅读13次
    1. 解决成员变量block循环
    __weak typeof(self) weakSelf = self;
     __strong typeof(weakSelf) strongSelf = weakSelf;
    

    用strongSelf修饰的self 必须为 __weak 修饰过以后的self
    strongSelf->解决成员变量,block循环引用

    1. 重写hittest
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
    
            CGPoint convertedPoint = [subview convertPoint:point fromView:self];
            UIView *hitTestView = [subview hitTest:convertedPoint withEvent:event];
            if (hitTestView) {
                return hitTestView;
            }
        }
        return [super hitTest:point withEvent:event];
    }
    
    1. 移除某个view的手势加在另一个上
    //移除scrollViewA原有手势操作
    NSMutableArray *list = [NSMutableArray arrayWithArray:scrollViewA.gestureRecognizers];
        for (UIGestureRecognizer *gestureRecognizer in list) {
            [scrollViewA removeGestureRecognizer:gestureRecognizer];
    }
    
    //将scrollViewB的手势操作加到scrollViewA中
    for (UIGestureRecognizer *gestureRecognizer in scrollViewB.gestureRecognizers) {
            [scrollViewA addGestureRecognizer:gestureRecognizer];
    }
    

    相关文章

      网友评论

          本文标题:iOS常用知识

          本文链接:https://www.haomeiwen.com/subject/hexjdxtx.html