2012-03-20 104 views
3

我的應用將僅適用於橫向方向。我有寬度,高度,x和y變量的主要問題。有沒有辦法交換所有的寬度,高度,x和y值,所以我不必扭轉我的應用程序中的所有座標? (即(X,Y)具有成爲(Y,X)和something.width必須被something.height。)iOS:如何交換橫向方向X和Y方向

這裏是我的問題的具體例子:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchPoint = [touch locationInView:unitArea]; 

    if (CGRectContainsPoint(self.view.frame, touchPoint)) 
    { 
     NSLog(@"released in area"); 
    } 
} 

這ISN」在景觀中工作......它使用了錯誤的座標,並且在某些地方,它會輸出「在區域中釋放」,但不會在視圖所在的實際區域中輸出。

unitArea bounds are <UIView: 0x6a52420; frame = (20 0; 300 480); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0x6a524a0>> 

這顯示爲我的視圖的邊界應該是(0 20; 480 300)。

編輯,瞭解更多信息:

這裏是我的(預製)定位方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
    } else { 
     return YES; 
    } 
} 

,並在項目總結我的「支持的設備取向」只設置爲橫向。

+0

如果您的應用程序確實處於橫向模式,那麼iOS將爲您處理座標轉換。 – CodaFi 2012-03-20 20:27:07

+0

已更新,提供更多信息。 – Derek 2012-03-20 20:42:02

+0

不應該觸摸[locationInView:self.view]? – CodaFi 2012-03-20 20:59:49

回答

3

在iOS中,窗口座標始終處於縱向模式。因此,您的rootViewController視圖的框架將始終處於縱向模式。嘗試在此視圖中插入另一個視圖。新視圖的框架必須將方向確定爲設備方向。