我希望我的子视图控制器标记为“navView”在应用程序启动时显示在屏幕外,并在按下按钮时显示动画。但是当我启动模拟器时,“navView”已经出现了。
- (void)viewDidLoad
{
[super viewDidLoad];
draw1 = 0;
navView.frame = CGRectMake(-568, 0, 320, 568);
newsView.frame = CGRectMake(0, 0, 320, 568);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sideNav:(id)sender {
if (draw1 == 0) {
draw1 = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
navView.frame = CGRectMake(0, 0, 320, 568);
newsView.frame = CGRectMake(1136, 0, 320, 568);
[UIView commitAnimations];
} else {
draw1 = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
navView.frame = CGRectMake(0, 0, 320, 568);
newsView.frame = CGRectMake(-500, 0, 320, 568);
[UIView commitAnimations];
答案 0 :(得分:0)
是在storyboard / xib中创建的navBar IBOutlet还是以编程方式创建它? 如果您在storyboard中添加它,请确保已创建与视图控制器的连接。现在它看起来不像那样,因为在大多数情况下,您可以访问自己的插座作为self.navBar。
如果您在viewDidLoad中以编程方式创建替换行:
navView.frame = CGRectMake(-568, 0, 320, 568);
使用:
YOURNAVBARCLASS *navView = [[YOURNAVBARCLASS alloc] initWithFrame:CGRectMake(-568, 0, 320, 568)];
[self.view addSubview:navView];
YOURNAVBARCLASS是从中创建navBar的类。
如果你的navBar是UINavigationBar的子类,你应该使用
[navigationController setNavigationBarHidden: YES animated:YES]