如何在UINavigationController中的所有视图前显示UIButton?

时间:2013-09-17 04:13:47

标签: iphone ios objective-c uinavigationcontroller uiwindow

我有一个UIButton,我希望在viewControllers UINavigationController UINavigationBar的所有viewController前面显示相同的位置,就像a {1}}一样UIWindow会 - 但在这种情况下,我希望按钮浮动在屏幕的左下角,如下所示:

enter image description here

我可以尝试手动将其添加到每个rootViewController,但我更愿意这样做而忘掉它。

将该按钮作为子视图添加到{{1}}似乎不起作用 - 它会在{{1}}后面。

更新:我已经找到了办法,但因为它涉及到iOS 7,所以在NDA解除之前我无法在此发布解决方案。好消息是,实现这一目标相当简单!一旦可以分享,我会发布一些内容。

3 个答案:

答案 0 :(得分:0)

  

我不认为这在ios中是可能的。你必须这样做   个人观点。

答案 1 :(得分:0)

创建一个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 :(得分:-1)

您只需在窗口上添加UIButton,就像

一样
 [self.window addSubview:Button];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

之后