UITapGestureRecognizer 不适用于自定义 UIView 类 [英] UITapGestureRecognizer not working on custom UIView class

查看:36
本文介绍了UITapGestureRecognizer 不适用于自定义 UIView 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个自定义视图类.我在我的视图控制器类中初始化它.我启用了用户交互,然后它也不起作用.我在类似的问题中搜索过它,但大多数都说要启用用户交互.
这是我写的代码.

I've made a custom view class. I'm initializing it in my view controller class. I've enabled user interaction then also it's not working. I've searched it in similar questions but most of them say to enable user interaction.
Here's the code I've written.

@interface ProfileCreatorViewController (){

SectionTitleView *ProfileTitle;
CGRect mainFrame;

}

@end

@implementation ProfileCreatorViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    mainFrame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + NAVBAR_HEIGHT, self.view.frame.size.width, self.view.frame.size.height);

    CGRect profileFrame = CGRectMake(mainFrame.origin.x + 5, mainFrame.origin.y, mainFrame.size.width - 20, 50);
    ProfileTitle = [[SectionTitleView alloc]initWithFrame:profileFrame withTitle:@"Profile" withUnderLineColor:[UIColor blackColor] withDownButton:[UIImage imageNamed:@"rightArrow"]];
    [self.view addSubview:ProfileTitle];

    UITapGestureRecognizer *recog = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(downButtonClicked)];
    [ProfileTitle addGestureRecognizer:recog];
    ProfileTitle.userInteractionEnabled = YES;

}


-(void) downButtonClicked{

    NSLog(@"clicked");
}

推荐答案

您可以在此处查看几项内容profileFrame 的高度和宽度都不是很小(打印 profileFrame)

You can check couple of things here profileFrame's height and width are not very small (print profileFrame)

ProfileTitle 不完全透明(当视图的 alpha 非常接近 0 时,Gesture 也不起作用)

ProfileTitle is not complete transparent (Gesture will also not work when view's alpha is very close to 0)

ProfileTitle 不会被任何其他视图遮挡(为此使用可视化调试器)

ProfileTitle is not obscured by any other view (use visual debugger for that)

这篇关于UITapGestureRecognizer 不适用于自定义 UIView 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆