2012-11-07 35 views
0

在我的UIViewController viewDidLoad中时,我有:子视图上的UINavigationController推动的viewController动画看起来不正确

myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
... 
myButton.frame = CGRectMake(0, 2, 40, 40); 
[self.navigationController.navigationBar addSubview:myButton]; 

按钮显示就好了。不,我推栈上的另一个视图 - 控制:

[self.navigationController pushViewController:vc animated:YES]; 

当然按钮仍然呈现所以我尽量掩藏它在viewWillDisappear并显示在viewWillAppear中,但过渡只是看起来不正确的。甚至用隐藏的通话交换超级通话的顺序也不正确。

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    myButton.hidden = YES; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    myButton.hidden = NO; 
    [super viewWillAppear:animated]; 
} 

我该怎么做才能让这个过渡看起来正确?谢谢。

+0

你不能使用[UINavigationItem](https://developer.apple.com/library/ios/#documentation/uikit/reference /UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/cl/UINavigationItem)来放置按钮? – Masa

+0

你是否解决了这个问题? UIView放置在viewcontroller上并使用UINavigationController进行动画时遇到同样的问题。 –

回答

0

而不是添加按钮子视图使用类似下面的

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:YourCustomView]; 
self.navigationItem.rightBarButtonItem = barButton; 
相关问题