在推送和弹出UIViewController时,将UIButton固定在屏幕上

时间:2012-07-11 02:04:26

标签: uiviewcontroller uinavigationcontroller uibutton

您好我目前有一个带导航控制器的导航应用程序,在应用程序内有多个视图,推出并弹回显示不同的xib,我想要做的是在屏幕右下角显示固定的按钮屏幕,点击时会将用户带到帮助xib,

然而,每当我按下或弹出一个视图时,按钮被动画并移动到位,我希望按钮在推动和弹出时不会移动并保持在视图顶部。< / p>

想知道是否有人可以帮助我,谢谢,萨米。

2 个答案:

答案 0 :(得分:0)

创建一个UIView类,创建UIButton并在所有viewcontrollers中创建该视图的对象,并将其添加到self.view。

答案 1 :(得分:0)

在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];    

    }