2011-01-28 42 views
0

這裏我使用3.2.5sdk和4.2 IOS,IPhone應用問題

我創建viewbased應用程序並添加基於舔

UINavigationController *navigation = [[UINavigationController alloc] 
    initWithRootViewController:viewController]; 
    [self.window addSubview:navigation.view]; 

現在我創建一個工具欄上的導航和該工具欄設置按鈕,一旦我rotrate我的模式從portrate TI景觀或反之亦然舔使用此代碼

- (BOOL)shouldAutorotateToInterfaceOrientation: 
    (UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 

- (void)willRotateToInterfaceOrientation: 
    (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 


if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 
{ 
    [toolbarview setFrame:CGRectMake(0, 979, 768, 45)]; 
    NSLog(@"the frame size is %f,%f,%f,%f",toolbarview.frame.origin.x, 
    toolbarview.frame.origin.y,toolbarview.frame.size.width, 
    toolbarview.frame.size.height); 
    NSLog(@"This is protrait mode");  
} 
else 
{ 
    [toolbarview setFrame:CGRectMake(0, 723, 1024, 45)]; 
    NSLog(@"the frame size is %f,%f,%f,%f",toolbarview.frame.origin.x, 
    toolbarview.frame.origin.y,toolbarview.frame.size.width, 
    toolbarview.frame.size.height); 
    NSLog(@"This is land mode"); 
} 

其工作正常,但一旦從IM的viewController導航到另一個p年齡,然後我改變我的模式舔這個代碼在第二頁上。

- (BOOL)shouldAutorotateToInterfaceOrientation: 
    (UIInterfaceOrientation)interfaceOrientation 
{ 
    // Overriden to allow any orientation. 
if ((interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || 
    (interfaceOrientation==UIInterfaceOrientationLandscapeRight)) 

{ 
    [viewController.toolbarview setFrame:CGRectMake(0, 723, 1024, 45)]; 
    NSLog(@"the frame size is %f,%f,%f,%f",viewController.toolbarview.frame.origin.x, 
    viewController.toolbarview.frame.origin.y, 
    viewController.toolbarview.frame.size.width, 
    viewController.toolbarview.frame.size.height); 
    NSLog(@"this is the Landscape Mode in home"); 

} 
else 
{ 
    [viewController.toolbarview setFrame:CGRectMake(0, 979, 768, 45)]; 
    NSLog(@"the frame size is %f,%f,%f,%f",viewController.toolbarview.frame.origin.x, 
    viewController.toolbarview.frame.origin.y, 
    viewController.toolbarview.frame.size.width, 
    viewController.toolbarview.frame.size.height); 
    NSLog(@"this is the portrait mode in home"); 

} 
return YES; 
} 

而根據第二頁模式,我想更改工具欄的位置,但它不工作。

+0

,它看起來像一個iPad應用程序,而不是iPhone – 2011-01-28 09:58:41

回答

0

在旋轉過程中,您不必擔心所有這些代碼。只需將工具欄放置在您想要的位置(看起來像在屏幕底部),然後設置自動調整大小的遮罩,以便它可以左右拉伸並保持在底部的固定位置。

Self.toolbar.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoResizingFlexibleTopMargin;

然後,無論何時您的視圖旋轉或調整大小,工具欄應保持固定在底部,並且它會縮小或水平增長以適應。

還是......我更傾向於將要建立在你的XIB工具欄和幀的大小設置自動尺寸面具那裏標籤3.

+0

感謝回覆我 – 2011-02-02 13:48:39