【问题标题】:Keep a UIButton fixed on screen when pushing and popping UIViewController推送和弹出 UIViewController 时将 UIButton 固定在屏幕上
【发布时间】:2012-08-03 02:49:22
【问题描述】:

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

但是,当我每次按下或弹出视图时,按钮都会被动画化并移动到位,我希望按钮在被按下和弹出视图时不要移动并保持在视图的顶部。

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

【问题讨论】:

    标签: uiviewcontroller uinavigationcontroller uibutton


    【解决方案1】:

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

    【讨论】:

    • 我将按钮添加为应用程序委托中窗口的子视图,并使用 alpha 属性相应地隐藏和显示按钮。
    • 做一件事创建一个uiview并在其上添加按钮。然后将视图子类添加为窗口按钮。相同的功能将适用于您。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多