gpt4 book ai didi

iphone - 如何在 UINavigationController 中的所有 View 前面显示一个 UIButton?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:00 24 4
gpt4 key购买 nike

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

enter image description here

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

将按钮作为 subview 添加到 UIWindow 似乎不起作用 - 它在 rootViewController 后面结束。

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

最佳答案

创建一个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

关于iphone - 如何在 UINavigationController 中的所有 View 前面显示一个 UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18841200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com