我正在尝试创建一个 picker
当一个 button
输入东西在 UITabBar
被按下。如果您查看 tumblrs iphone 应用程序,您就会明白我的意思。我假设他们正在展示 UIView
无论如何viewcontroller
用户当前处于开启状态。我该怎么做?
最佳答案
这个问题对我来说更像是一个自定义标签栏按钮问题,我认为 tumblr 所做的是在标签栏中间添加一个自定义按钮,并在单击该按钮时呈现一个模态视图 Controller 。
我对我的测试项目做了一个非常快速的测试,一些数字是为了测试目的而硬编码的,你可能需要稍微调整一下。
viewWillAppear
)- (void)viewWillAppear:(BOOL)animated
{
UIImage *buttonImage = [UIImage imageNamed:@"classic-batman-logo.jpg"];
UIImage *highlightImage = [UIImage imageNamed:@"classic-batman-logo.jpg"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 60, 50);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
button.center = CGPointMake(self.tabBarController.tabBar.center.x , 30);
[button addTarget:self action:@selector(centerButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.tabBarController.tabBar addSubview:button];
}
- (void)centerButtonClicked
{
UIViewController *vc = [[UIViewController alloc]init];
vc.view.backgroundColor = [UIColor redColor];
[self presentViewController:vc animated:YES completion:nil];
}
这只是我做了一个 10 分钟的测试,应该是这样的:
也许您需要注意以下几点:
希望这能让您对如何实现这一目标有一些粗略的了解。
关于ios - 显示来自 UITabBar 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21836065/