首页 > 其他 > 详细

V4L2文档翻译(八)

时间:2014-04-15 04:26:49      阅读:569      评论:0      收藏:0      [点我收藏+]

此QA来自苹果开发者库,贴下地址:

https://developer.apple.com/library/ios/qa/qa2013/qa1812.html#//apple_ref/doc/uid/DTS40014336


故障原因:当控件在父视图的区域外,区域外的控件虽然可以显示出来,但是无法响应点击事件。

解决办法:继承父类,Override下 hitTest方法:代码如下:


//
//  OutMaskView.h
//  testOutsideHit
//
//  Created by twb on 14-4-14.
//  Copyright (c) 2014年 twb. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface OutMaskView : UIView

@property (nonatomic, strong) UIView *targetView;

@end

//
//  OutMaskView.m
//  testOutsideHit
//
//  Created by twb on 14-4-14.
//  Copyright (c) 2014年 twb. All rights reserved.
//

#import "OutMaskView.h"

@implementation OutMaskView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    // Convert the point to the target view‘s coordinate system.
    // The target view isn‘t necessarily the immediate subview
    CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self];
    
    if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) {
        
        // The target view may have its view hierarchy,
        // so call its hitTest method to return the right hit-test view
        return [self.targetView hitTest:pointForTargetView withEvent:event];
    }
    
    return [super hitTest:point withEvent:event];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

然后再视图控制器,也即controller中得

viewDidLoad方法种设置您的目标视图,也即你不能接受事件的视图。

//
//  ViewController.m
//  testOutsideHit
//
//  Created by twb on 14-4-14.
//  Copyright (c) 2014年 twb. All rights reserved.
//

#import "ViewController.h"
#import "OutMaskView.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIButton *testButton;
@property (weak, nonatomic) IBOutlet OutMaskView *maskView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.maskView.targetView = self.testButton;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)testMask:(id)sender
{
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"信息" message:@"现在可以点击了!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
    [av show];
}


@end

V4L2文档翻译(八),布布扣,bubuko.com

V4L2文档翻译(八)

原文:http://blog.csdn.net/airk000/article/details/23686685

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!