3

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

在此处输入图像描述

我可以尝试手动将其添加到 eachviewController中,但我更愿意执行一次并忘记它。

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

更新:我已经找到了一种方法,但是因为它涉及到 iOS 7,所以在解除 NDA 之前我不能在这里发布解决方案。好消息是,实现这一点相当简单!一旦可以分享,我会发布一些东西。

4

3 回答 3

0

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

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

按钮面板类:

//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
于 2013-09-17T04:51:33.857 回答
-1

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

 [self.window addSubview:Button];

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

于 2013-09-17T04:45:14.700 回答
-1

我认为这在 ios 中是不可能的。您必须对所有视图进行单独处理。

于 2013-09-17T04:26:09.093 回答