我創造的是iOS庫不工作。從AppDelegate啓動時,我的庫將在屏幕頂部創建一個按鈕。UIButton的點擊,如果子視圖的UIWindow
我創建了按鈕,它被顯示出來。但是當我點擊時,目標方法不會被激發。
這是怎麼了我創建的按鈕,然後在庫
- (void) addLoginButton {
UIWindow *appWindow = [[[UIApplication sharedApplication] delegate] window];
UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
[loginButton setFrame:CGRectMake((appWindow.frame.size.width/2)-35, 20, 70, 20)];
[loginButton setBackgroundColor:[UIColor blueColor]];
[loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
[loginButton addTarget:self action:@selector(auLoginClicked) forControlEvents:UIControlEventTouchUpInside];
[appWindow addSubview:loginButton];
if([appWindow.rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navCon = (UINavigationController *)(appWindow.rootViewController);
if (!navCon.navigationBar.isHidden) {
navCon.navigationBar.layer.zPosition = 0;
}
}
loginButton.layer.zPosition = 5;
}
- (void) auLoginClicked {
NSLog(@"Hello");
}
我認爲你必須採取隨後的UIView在窗口上添加一層。 uiview應該添加按鈕。試試這個 – ajjjjjjjj
不要使用圖層'loginButton.layer.zPosition = 5;' –
使用bringSubViewFront,如果不是。 –