嗨我想实现这个动画效果(使用故事板),当用户点击标签栏(比如第二个标签栏项目)时,它会像模态视图一样显示相应的视图(向上显示到屏幕)
我当前的方法是委托标签栏控制器到标签栏并重写
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(@"rawr");
NSLog(@"inside tab bar did select, index is %d", self.selectedIndex);
if (item == [self.tabBar.items objectAtIndex:1]) {
//item.title = @"modal view";
NSLog(@"going to promote as modal view");
CBTab2ViewController* modalViewController = [[CBTab2ViewController alloc] init];
[self presentViewController:modalViewController animated:YES completion:nil];
}
}
问题是,显示的视图是黑屏,任何想法如何正确实现?
我的源代码可以在下面找到一个链接: https://www.dropbox.com/s/6rd6ek59xf0yiq4/testtabbar.zip
答案 0 :(得分:2)
更改行:
CBTab2ViewController* modalViewController = [[CBTab2ViewController alloc] init];
[self presentViewController:modalViewController animated:YES completion:nil];
对于这个(如果你的故事板名称是" MainStoryBoard"):
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
CBTab2ViewController * modalViewController = (MyViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"CBTab2ViewController"];
[self presentViewController:modalViewController animated:YES completion:nil];