【发布时间】:2015-01-23 03:31:00
【问题描述】:
我正在试验一个自定义类按钮,在触摸启动时显示 UIView。 我有一个 UIButton 类名为 TapInButton。这是代码。
#import "TapInButton.h"
#import "TapInViewController.h"
@interface TapInButton()
@property (nonatomic,strong) TapInViewController * tapIn;
@end
@implementation TapInButton
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.tapIn = [[TapInViewController alloc] initWithNibName:@"TapIn" bundle:nil];
self.tapIn.view.frame = CGRectMake(0, 50, 300, 500);
self.tapIn.view.backgroundColor = [UIColor redColor];
[self.superview addSubview:self.tapIn.view];
}
如您所见,我导入生成 xib 文件的 TapInViewController。 当用户单击具有自定义类 TapInButton 的 Tapin 按钮时。 它显示 xib 文件。见下图
我成功地将 xib 添加到主 ViewController 但问题是我无法单击 xib 文件中的按钮。我的代码中是否缺少某些内容?或者这是否可以在自定义 UIButton 中生成 uiview?
我知道生成 xib 文件但不使用自定义按钮的另一种方法。如果可能的话,我只想澄清一下我的想法。希望得到您的建议或解释。提前致谢
【问题讨论】:
-
你有 userInteractionEnabled 吗?
-
我也不确定这是否完全必要,但您通常会调用 [super touchesBegan:touches withEvent: event];在方法的开头。
-
@JoshGafni 抱歉回复晚了。我只是猜测这是否有效。我是这个自定义课程的新手。我尝试启用 userInteractionEnable 但输出相同。我无法单击我的 xib 文件中的按钮。
标签: ios uiview uiviewcontroller uibutton