CGRectMake 适用于不同的 iphone ipad 方向
对于以下代码,我需要根据 iphone 和 ipad 方向设置不同的 UIIMageView 位置。
// Animated images - centered on screen
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(
(SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2),
(SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
IMAGE_WIDTH, IMAGE_HEIGHT)];
因为 CGRect 对于 ipad 纵向、iphone 纵向、ipad 横向和 iphone 横向会有所不同。
我该怎么做
if (Ipad Portrait orientation)
{
code with different position using CGRectMake (...............)
}
if (Iphone Portrait orientation)
{
code with different position using CGRectMake (...............)
}
if (Ipad Landscape orientation)
{
code with different position using CGRectMake (...............)
}
if (Iphone Landscape orientation)
{
code with different position using CGRectMake (...............)
}
For following code I need to set different UIIMageView Positions according to iphone and ipad orientation.
// Animated images - centered on screen
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(
(SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2),
(SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
IMAGE_WIDTH, IMAGE_HEIGHT)];
As CGRect will be different for ipad portrait,iphone portrait, ipad landscape and iphone landscape.
How do I do this
if (Ipad Portrait orientation)
{
code with different position using CGRectMake (...............)
}
if (Iphone Portrait orientation)
{
code with different position using CGRectMake (...............)
}
if (Ipad Landscape orientation)
{
code with different position using CGRectMake (...............)
}
if (Iphone Landscape orientation)
{
code with different position using CGRectMake (...............)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 UIViewController 的 interfaceOrientation 属性。它将为您提供以下值之一:
UIInterfaceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
您的代码如下所示:
You can use the UIViewController's interfaceOrientation property. It will give you one of the following values:
UIInterfaceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
Your code would look like:
您可以使用 区分 iPhone 和 iPad
,也可以使用 区分纵向和横向,
现在将其结合起来,即可根据您的喜好进行自定义。
You can differentiate between iPhone and iPad with
and you can differentiate between portrait and landscape with
Now combine this to get the customization as you like.