0

iPad の自動回転に取り組んでいますが、奇妙な問題に直面しています。

問題は、iPadを縦向きビューとして使用し始め、iPadを横向きに回転させる場合です。ポートレートのサイズを表示していますが、ランドスケープは表示していません。同様に、iPad を横向きビューとして使用し始め、iPad を縦向きビューに回転させます。横のサイズを表示していますが、縦のサイズは表示していません。以下のコードを使用してオブジェクトのサイズを変更しています

- (void)viewDidLoad {

 UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        table.frame = CGRectMake(83, 600, 550, 275);
           im.frame = CGRectMake(0, 62, 775, 70);
          im1.frame = CGRectMake(0, 135, 775, 40);
        im2.frame = CGRectMake(60, 325, 650, 550);
         l17.frame = CGRectMake(0, 62, 775, 70);
        l16.frame = CGRectMake(85, 145, 780, 40);
           l15.frame = CGRectMake(83, 200, 600, 40);
        img.frame = CGRectMake(550, 300, 150, 110);
        l18.frame = CGRectMake(28, 550, 650, 40);
           b7.frame = CGRectMake(83, 880, 600, 40);
        //[self.view addSubview:table];

    }

    [super viewDidLoad];
}

何がうまくいかないのか教えてください。

4

2 に答える 2

0
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {

    if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
        table.frame = CGRectMake(83, 600, 550, 275);
        im.frame = CGRectMake(0, 62, 775, 70);
        im1.frame = CGRectMake(0, 135, 775, 40);
        im2.frame = CGRectMake(60, 325, 650, 550);
        l17.frame = CGRectMake(0, 62, 775, 70);
        l16.frame = CGRectMake(85, 145, 780, 40);
        l15.frame = CGRectMake(83, 200, 600, 40);
        img.frame = CGRectMake(550, 300, 150, 110);
        l18.frame = CGRectMake(28, 550, 650, 40);
        b7.frame = CGRectMake(83, 880, 600, 40);
    else
        tableView.frame = CGRectMake(0,73,320,390);
        --
        --

}

このように試しましたか?

于 2013-04-01T05:58:39.490 に答える
0

向きをチェックするコードが機能しているかどうか

コード ::

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    ......
}

チェック方法 ::

-(void)orientationChanged {

   NSLog(@"Orientation Changed..!!");

   UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

   //Lanscape View
   if (interfaceOrientation == UIInterfaceOrientationLandscapeRight
    || interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
   {
       table.frame = CGRectMake(83, 600, 550, 275);
       .....
   }

   //Portrait View
   else
   {
       table.frame = CGRectMake(x, y, w, h);
       .....
   }
}

方向変更メソッドのコード

PCH ファイルでは、

#define IOS_OLDER_THAN_6        ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )

.m ファイルでは、

//For Less than IOS 6

#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
   return toInterfaceOrientation;
}
#endif

// For Newer than IOS 6.
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
   return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
   return (UIInterfaceOrientationMaskAll);
}
#endif

うまくいけば、それはあなたに役立つでしょう.

ありがとう。

于 2013-04-01T06:35:46.430 に答える