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 回答