如何以横向模式以肖像方式显示?

时间:2011-11-11 04:34:23

标签: iphone

我在Iphone中有一个计算器屏幕,当我以纵向显示它时,我想以横向模式显示计算器屏幕,并且还要改变方向,如何?

我尝试了源代码:

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

它是第一次使用纵向仅启动横向模式,但改变方向不起作用,任何人帮助我。

3 个答案:

答案 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)]; 

答案 1 :(得分: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.

答案 2 :(得分: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; 
    }