2013-12-08 58 views
0

我希望我的子視圖控制器標記爲「navView」,當應用程序啓動時顯示在屏幕外,當按下按鈕時動畫顯示。但是當我啓動模擬器時,「navView」已經出現。ViewDidLoad的問題

- (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

在'viewDidLoad',你確定'navView'不是'nil'? – rmaddy

回答

0

navBar IBOutlet,是在storyboard/xib中創建的,還是以編程方式創建它? 如果您在故事板中添加它,請確保您已創建與視圖控制器的連接。現在看起來不是這樣,因爲在大多數情況下,您可以通過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是導航欄,從創建的類。

如果你的導航欄是UINavigationBar的子類,你應該使用

[navigationController setNavigationBarHidden: YES animated:YES]