1

次のコードでは、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 (...............)
}
4

2 に答える 2

3

UIViewController の interfaceOrientation プロパティを使用できます。次のいずれかの値が得られます。

UIInterfaceOrientationPortrait、UIInterfaceOrientationPortraitUpsideDown、UIInterfaceOrientationLandscapeLeft、UIInterfaceOrientationLandscapeRight

コードは次のようになります。

if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
    ...
}
else if    // etc.
于 2011-06-20T17:06:10.063 に答える
0

iPhoneとiPadを区別することができます

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // The device is an iPad running iPhone 3.2 or later.
}
else
{
     // The device is an iPhone or iPod touch.
}

縦向きと横向きを区別できます

if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
     // The device is in landscape.
}
else
{
     // The device is in portrait.
}

これを組み合わせて、好きなようにカスタマイズしてください。

于 2011-06-20T17:12:44.373 に答える