【问题标题】:How to display a UIButton in front of all views in UINavigationController?如何在 UINavigationController 中的所有视图前显示 UIButton?
【发布时间】:2013-09-21 09:08:48
【问题描述】:

我有一个UIButton,我想将它显示在我的UINavigationController 的所有viewControllers 前面的相同位置,与UINavigationBar 的方式非常相似 - 但是在这种情况下,我希望按钮浮动在屏幕的左下角,如下所示:

我可以尝试手动将其添加到每个viewController,但我更愿意这样做一次然后忘记它。

将按钮作为子视图添加到 UIWindow 似乎不起作用 - 它最终出现在 rootViewController 后面。

更新:我已经想出了一个办法,但是因为它涉及到 iOS 7,所以我不能在这里发布解决方案,直到 NDA 被解除。好消息是,实现这一点相当简单!一旦可以分享,我会发布一些内容。

【问题讨论】:

  • 制作一个 UIView 并添加到每个 VC 上
  • 是的,但这正是我试图避免在这里做的事情。我希望它漂浮在所有视图控制器的前面,而不是让它在过渡期间移动。
  • @bryanjclark iOS 7 NDA 已解除。你做了什么?
  • @TomHamming 我实现了自定义 UINavigationController 转换,并在转换期间在视图控制器之间移动了按钮。

标签: iphone ios objective-c uinavigationcontroller uiwindow


【解决方案1】:

创建一个NSObject类buttonPanel并分配按钮,你可以调用按钮面板如下:

buttonPanel * buttonPanel = [[buttonPanel alloc] init];
buttonPanel.delegate = self;
[buttonPanel showButtonWithNavigationController:self.navigationController inView:self.parentViewController.view];

ButtonPanel 类:

//ButtonPanel.h
#import <Foundation/Foundation.h>

@class ButtonPanel;

@protocol ButtonPanelDelegate <NSObject>

-(void) ButtonPanel:(ButtonPanel*) buttonPanel ;

@end

@interface ChatMessagePanel : NSObject<UIActionSheetDelegate> {

    UINavigationController *navigationController;

    id<ButtonPanelDelegate> delegate;
}

@property(nonatomic,retain) UINavigationController *navigationController;
@property (nonatomic,retain) id<ButtonPanelDelegate> delegate;

-(void)showButtonWithNavigationController:(UINavigationController*) navigationController inView:(UIView*) view;

@end


//  ButtonPanel.m


#import "ChatMessagePanel.h"

@implementation ButtonPanel

@synthesize userListModal,delegate,navigationController;

-(void)showMessageWithNavigationController:(UINavigationController*) _navigationController inView:(UIView*) view
{
    self.navigationController = _navigationController;

    baseViewWidth = view.frame.size.width;
    baseViewHeight = view.frame.size.height;

    incomingRequestActionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
    [incomingRequestActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    [incomingRequestActionSheet showInView:view];


    UIButton *blockUserBttn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
    [blockUserBttn setTitle:NSLocalizedString(@"BLOCK_USERS",@"") forState:UIControlStateNormal];
    [blockUserBttn setBackgroundColor:[UIColor clearColor]];
    [blockUserBttn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];


    UIBarButtonItem *blockUserBarBttn = [[UIBarButtonItem alloc] initWithCustomView:blockUserBttn];

    [optionToolBar setItems:[NSArray arrayWithObjects:blockUserBarBttn, nil]];
    [incomingRequestActionSheet addSubview:optionToolBar];

}

-(void)buttonAction:(id) sender
{

}

@end

【讨论】:

    【解决方案2】:

    你可以简单地在窗口上添加UIButton

     [self.window addSubview:Button];
    

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];之后

    【讨论】:

    • 实际上,这是行不通的——按钮在 UIWindow 的所有子视图后面结束,包括根视图控制器。
    • 只有当键盘在它前面时它才会落后...否则它会留在前面...请检查...。
    【解决方案3】:

    我认为这在 ios 中是不可能的。你必须做 个人所有视图。

    【讨论】:

    • 这对您有帮助吗?
    • 不,很遗憾。不过,感谢您的尝试! :)
    • 我想通了,但由于它使用 iOS 7 的东西,我还不能发布它。一旦 NDA 被解除,就会这样做!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多