2013-04-01 12 views
0

我正在使用Autorotation for 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]; 
} 

請問我最近出了什麼問題?

回答

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); 
     -- 
     -- 

} 

你試過這樣嗎?

+0

這是不是通過這種方法 –

+0

面臨的大小問題,而只有旋轉的權利? – wesley

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 

希望,這將是對您有所幫助。

謝謝。