简体   繁体   English

UIbutton框架和addtarget不同

[英]UIbutton frame and addtarget is different

I make custom view and there create button add on view. 我进行自定义视图,并在视图上添加创建按钮。 In View Controller In View控制器

MyCustomView *customView = [[MyCustomView alloc] init];
[customView.button addTarget:self action:@selector(goodTry) forControlEvents:UIControlEventTouchUpInside];

But if I touch my button in frame only down mean line is touchable, upper of mean line addTarget does not working. 但是,如果我在框架中触摸我的按钮,只有向下的中线是可触摸的,中线的上端addTarget不起作用。

 ----
|\   |      
|*\  |
|**\ |
|***\| 
 ----

-- It is my button frame. -这是我的按钮框。 Where *** - it is working. *** -在工作。 Where empty place doesn't work. 空旷的地方不起作用的地方。

Thanks for your help. 谢谢你的帮助。

为按钮添加背景色,并检查按钮的放置方式和位置。如果按钮位于自定义视图之外,则无法对该外部部分执行操作。

Check that your button frame lies inside the parent's frame. 检查按钮框是否位于父母的框内。 Area of button outside Parent's frame freezes and doesn't respond to touch events. Parent框外的按钮区域冻结,并且不响应触摸事件。 Set clipToBounds = YES; 设置clipToBounds = YES; on button to test it. 按钮进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone UIButton addTarget不起作用 - iPhone UIButton addTarget not working 在[UIButton addTarget]中传递自定义数据 - Passing custom data in [UIButton addTarget] 如何在UIButton中实现addTarget属性 - how to implement addTarget property in a UIButton addTarget 不适用于在 Swift 中创建的 UIButton - addTarget not working for UIButton created in Swift UIButton addTarget:action:forControlEvents:[NSObject doesNotRecognizeSelector:]中的结果 - UIButton addTarget:action:forControlEvents: results in [NSObject doesNotRecognizeSelector:] UIButton类参考文档上的addTarget方法 - addTarget method on UIButton Class reference document UIButton 块相当于 addTarget:action:forControlEvents: 方法? - UIButton block equivalent to addTarget:action:forControlEvents: method? 使用带有两个参数的UIButton addTarget时无法识别的选择器 - Unrecognized selector when using UIButton addTarget with two parameters 具有自定义视图的UIButton-addTarget:action:forControlEvents:不起作用 - UIButton with custom view - addTarget:action:forControlEvents: does not work 在.xib文件中创建的UIButton是IBAction还是[UIButton addTarget:action:forControlEvents:]? 哪种方法更好? - IBAction or [UIButton addTarget:action: forControlEvents:] for UIButton created in .xib file? Which is the better approach?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM