码迷,mamicode.com
首页 > 其他好文 > 详细

子控件超出父控件响应

时间:2015-05-21 22:17:09      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

// 事件传递给subview
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
   CGPoint subviewP = [self convertPoint:point toView:_subview];
    
    if ([_subview pointInside:subviewP withEvent:event]) {
        return _subview;
    }else
    {
        return [super hitTest:point withEvent:event];
    }
}

// 手指移动
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint location =  [touch locationInView:self];
    
    CGPoint pre = [touch previousLocationInView:self];
    
    CGFloat offsetX = location.x - pre.x;
    CGFloat offsetY = location.y - pre.y;
    
    CGPoint center = self.center;
    center.x += offsetX;
    center.y += offsetY;
    
    self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY); 
}

 

子控件超出父控件响应

标签:

原文地址:http://www.cnblogs.com/songxing10000/p/4520615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!