linux显示iphone屏幕,iphone 横屏 显示

View Rotation using Transforms

The default view coordinate system assumes a portrait orientation. To launch in landscape, you have to change the orientation of your view, and the way you do this is by modifying the view's affine transform. Translating a view shifts all its subviews.

After your views are loaded into memory, you need to reorient them to landscape mode by doing the following:Find the center point of your application’s content area.

Rotate your views 90 degrees around that center point.

The exact center point of your application’s content area can vary and is dependent on your interface design. Applications that do not display the status bar or applications that display a translucent status bar typically have a content area that matches the screen bounds. Applications that display an opaque status bar typically have a content area that does not include the area occupied by the status bar. This latter scenario is more common and is also a little more challenging to implement correctly. As a result, the rest of this Tech Note shows you how to perform a rotation on an interface that uses an opaque status bar.

When your landscape view is loaded from its nib file, its center point is initially set to match the center point of the screen, as shown in the Figure below: “Coordinates used when laying out content in landscape mode”. Because the view in the example does not occupy the area under the status bar, however, the initial center point is incorrect. To find the correct center point, you can use the location and size of the status bar to aid your computations. The status bar’s height represents the width of the landscape-oriented content area. Similarly, the status bar’s x-origin represents the height of the landscape-oriented content area. Using these values along with the origin point of (0, 0), you can compute the correct center point of the content area and use that value to reposition your view before applying a rotation transform.Figure 1  Coordinates used when laying out content in landscape mode.

d55c21f42c9a09a75602a361288b729f.png

The Listing below "Reorienting a view to landscape mode” shows the viewDidLoad: method of a controller object whose views are oriented for landscape mode at launch. As previously described, this method uses the height and x-origin of the status bar to compute the center point of the landscape-oriented content area. It then shifts the center of the portrait-oriented view to that location and rotates the view into the proper orientation.

Listing 2  Reorienting a view to landscape mode.

- (void)viewDidLoad

{

[super viewDidLoad];

if ([[UIDevice currentDevice].systemVersion floatValue] < 2.1)

{

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

if (orientation == UIInterfaceOrientationLandscapeRight)

{

CGAffineTransform transform = self.view.transform;

// use the status bar frame to determine the center point of the window's content area.

CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];

CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);

CGPoint center = CGPointMake(bounds.size.height / 2.0, bounds.size.width / 2.0);

// set the center point of the view to the center point of the window's content area.

self.view.center = center;

// Rotate the view 90 degrees around its new center point.

transform = CGAffineTransformRotate(transform, (M_PI / 2.0));

self.view.transform = transform;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值