これを appdelegate で使用すると、すべての画面にボタンを表示するのに役立ちます。このボタンを処理する必要がある場合は、viewcontrollerAppdelegate.h をビュー コントローラーにインポートします。そして使う
UIAppDelegate.SettingButton.hidden=True;
またはこのように。ちょうど試して
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[settingButton addTarget:self action:@selector(settingButtonPressed:)forControlEvents:UIControlEventTouchDown];
UIImage *buttonImage = [UIImage imageNamed:@"icon-lb.png"];
[settingButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[settingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
settingButton.frame = CGRectMake(265, 17, 40, 45);
settingButton.hidden=TRUE;
[self.window addSubview:settingButton];
[self.window makeKeyAndVisible];
return YES;
}
- (void)settingButtonPressed:(id) sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"settingButtonPressed" object:nil];
setting *obj = [[setting alloc] initWithNibName:@"setting" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:obj];
navController.navigationBar.tintColor=[UIColor blackColor];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.window addSubview:navController.view];
[navController.view setFrame:CGRectMake(0,480,320,480)];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:navController.view cache:YES];
[navController.view setFrame:CGRectMake(0,0,320,480)];
[UIView commitAnimations];
}