我正在使用 Parse anypic 教程,我想创建一个不同的 UI。但是我有一些麻烦。
所以,我的 ViewController 是这样的:
@interface PAPHomeViewController ()
@property (nonatomic, strong) PAPSettingsActionSheetDelegate *settingsActionSheetDelegate;
@property (nonatomic, strong) UIView *blankTimelineView;
@end
@implementation PAPHomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"LoadView is called");
// Present Anypic UI
[self presentUI];
}
-(void) presentUI {
/*UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[backgroundImageView setImage:[UIImage imageNamed:@"DefaultAnypic.png"]];
self.view = backgroundImageView;*/
// Settings button
self.settingsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.settingsButton addTarget:self
action:@selector(settingsButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.settingsButton setTitle:@"Settings" forState:UIControlStateNormal];
self.settingsButton.frame = CGRectMake(200.0, 200.0, 100.0, 100.0);
[self.view addSubview:self.settingsButton];
}
它的 .h 文件是这样的:
@interface PAPHomeViewController : PAPPhotoTimelineViewController
@end
PAPPhotoTimelineViewController 也是一个单独的 ViewController,Home 从它扩展,它是一个 tableViewController,它也调用 ViewDidLoad。
问题:
通过上面的代码,我看到了我的按钮,我可以点击我的按钮。
但是,如果我取消对背景的注释,我确实看到了背景,我确实看到了按钮,但无法点击 - 就像没有识别到按钮上的触摸一样。
我也很困惑,现在我正在扩展另一个也实现了 viewDidLoad 的 ViewController,为什么它们都被调用,以什么顺序等。
最佳答案
你不应该为你的 self.view
分配一个新的 UIView
。
而不是 self.view = backgroundImageView;
,就像添加一个随机 View 一样。
[self.view addSubview:backgroundImageView];
这样做,您将按照正确的方式添加 subview :您的 backgroundImageView
将显示在您的 View 中,您的按钮将添加到它上面。
关于ios - 添加背景时按钮被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26691740/