2011-11-11 130 views
0

我有一個Iphone的計算器屏幕,當我啓動它以縱向顯示時,但我想從縱向顯示橫向模式的計算器屏幕,也改變方向,怎麼樣?如何以橫向顯示橫向模式?

我試過的源代碼:

 self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = CGAffineTransformMakeRotation((M_PI * (90)/180.0)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 480, 320); 

它用於首次推出只在縱向橫向模式,但改變方向不工作,任何一個可以幫助我。

+0

我想你想在這兩個方向上運行你的應用程序... ..英寸右..否則請告訴我你確切想要做什麼..... –

回答

1

試試這個:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 
[[self view] setBounds:CGRectMake(0, 0, 480, 320)]; 
[[self view] setCenter:CGPointMake(160, 240)]; 
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI/2)]; 
+0

我使用這些代碼,它是在縱向模式下啓動景觀,但改變方向不工作,謝謝 – sankar

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

Now make use of any one method for ur rotation 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 
    Hope this help. 
0

此地same question

我的沙盒應用程序: https://github.com/comonitos/programatical_device_orientation

解決辦法很簡單:

接口(H文件):

BOOL rotated; 

實施(M檔): 1.改寫

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

2調用[自我設置]

-(void) setup { 
    rotated = YES; 
    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft]; 
    rotated = NO; 
    }