iOS button被view遮住,想点击怎么破

UIView的提供了这个方法:- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;

1.创建CustomView继承自UIView :

CustomView.h

@property (strong,nonatomic)NSArray * passthroughViews;

@property (nonatomic)BOOL testHits;

-(BOOL) isPassthroughView: (UIView*) view;

CustomView.m

-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event{

if(self.testHits){

return nil;

}

if(!self.passthroughViews

|| (self.passthroughViews && self.passthroughViews.count == 0)){

return self;

} else {

UIView *hitView = [super hitTest:point withEvent:event];

if (hitView == self) {

self.testHits = YES;

CGPoint superPoint = [self.superview convertPoint:point fromView:self];

UIView *superHitView = [self.superview hitTest:superPoint withEvent:event];

self.testHits = NO;

if ([self isPassthroughView:superHitView]) {

hitView = superHitView;

}

}

return hitView;

}

}

- (BOOL)isPassthroughView:(UIView *)view {

if (view == nil) {

return NO;

}

if ([self.passthroughViews containsObject:view]) {

return YES;

}

return [self isPassthroughView:view.superview];

}

2.创建ViewController继承自UIViewController :

ViewController.m

- (void)viewDidLoad {

[super viewDidLoad];

self.passthroughButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[self.passthroughButton setTitle:@"Passthrough" forState:UIControlStateNormal];

[self.view addSubview:self.passthroughButton];

self.passthroughButton.frame = CGRectMake(20, 50, 120, 28);

[self.passthroughButton addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];

CustomView *customView = [[CustomView alloc] initWithFrame:CGRectMake(80, 10, 300, 200)];

customView.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:.5];

//customView.passthroughViews = [NSArray arrayWithObject:self.passthroughButton];

[self.view addSubview:customView];

}

时间: 2024-10-21 19:37:26

iOS button被view遮住,想点击怎么破的相关文章

iOS之Container View获取ViewController

最近使用Container View来在主View Controller建立自己的子Controller,可是遇到问题,不知道如何用代码获取Controller View附带的View Controller. 本想获取了其附带的View Controller,在里面设置代理,然后再主View Controller中实现代理方法,找了很多资料,解决方案如下. 建立一个.h与.m文件,使其关联Container view附带的View Controller,在里面设置代理. 点击Segue,设置Id

如何采用绝对坐标的方式动画方式移动view和如何点击view的时候获取它的cachebitmap并移动

Layout: <?xml version="1.0" encoding="UTF-8"?> <com.example.android_test.MyDragLayer xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootView" android:layout_width="fill_par

Android View分区域点击实现方案——1.根据坐标范围

Android View分区域点击实现方案--1.根据坐标范围 引言 好哒,很久没更新博客里关于Android的博文了,有小伙伴经常在群里问或者私聊我: 读者:"Android进阶什么时候出,写什么Git,数据结构,专心写Android进阶-"之类的话, 对此表示我很无奈: 我: 读者: 我:好吧,怪我- 嗯,不是自己不想写,主要是自己现在的事情比较多,接触的东西越多,学的东西越多, 除了要完成公司项目外,还有一些其他的东西要学,前段时间刚做完电台的项目,现在 要和另外一个同事搞Lau

button设为UICustomType后点击无高亮效果

今天在cell上加了一个button,设了image secondButton.buttonType = UIButtonTypeCustom; [secondButton setImage:image_2 forState:UIControlStateNormal]; 但是点击上去无高亮效果,经查找 发现两个问题 1.应该设backGroundImage [secondButton setBackgroundImage:image_2 forState:UIControlStateNormal

ios 获取当前view的controller

 //获取view的controller  - (UIViewController *)viewController {     for (UIView* next = [self superview]; next; next = next.superview) {         UIResponder *nextResponder = [next nextResponder];          if ([nextResponder isKindOfClass:[UIViewControll

iOS中CollectionView由于多次点击造成错误的解决方案

iOS中CollectionCiew由于多次点击,会给程序造成错误. 这个时候,我们可以用过手势类来进行判断和过滤. 但是,有一个快捷的解决方法,那就是给用户响应增加延时操作. 具体代码如下: [collectionView setUserInteractionEnabled:NO]; [collectionView performSelector:@selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:

用ios代码做view

import“ViewController.h" @interface ViewController() @end @implementation ViewController -(void)viewDidload { [super viewDidload]; UIView *redview=[[UIView alloc]init]; redview.frame=CGRectMake(0,0,300,100); redview.backgroundcolor=[UIColor redColor]

ios中使view向左移动,且右边不动

ios中使view向左移动,且右边不动 by 伍雪颖 -(void)signUpAndLoginAnimation:(BOOL)showSignUp { CGFloat LogInWidthChange = (showSignUp)?-120:120; [UIView animateWithDuration:0.3f animations:^{ CGRect newFrame = self.logInView2.frame; newFrame.origin.x -= LogInWidthChan

关于iOS UIWebView 加载网页,点击网页内某些控件导致 Application &#39;UIKitApplication:xxx.xxx.xxx&#39; was killed by jetsam.

问题:公司用的腾讯问卷系统,内嵌在我们应用或游戏的自定义UIWebView里面展示,发现在iOS 10 以下系统,点击圆形勾选框 会大概率出现闪退. 通过联调发现:报了这样一个警告Application 'UIKitApplication:xxx.xxx.xxx' was killed by jetsam. 然后没有更多的信息了. (连接真机调试,当发生闪退的时候,设备会同时跟Xcode断开连接,没有更多的错误堆栈,另外设备也没有记录下更多的Crash log 提供定位.) 最后从以下获取到近似