2012-11-01 19 views
3

它在縱向開始時效果非常好,而且當您從縱向旋轉到橫向和後方時也可以使用。iPad在景觀中開始只接觸768x768內

在橫向啓動時不起作用。但是當它從風景旋轉到縱向並返回時,它就會起作用。

在風景模式下啓動,屏幕不與任何觸摸屏哪裏coordinateX大於768

在代碼中會發生什麼事是,我使用的狀態欄方向來確定原來的方向和手動旋轉每個視圖響應。視圖正確顯示但無法正常接觸。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

將每個子視圖旋轉:

然後在iPad上開始轉動我的根視圖控制器將被調用。

根控制器:

- (void)loadView { 
    self.view = [[UIView alloc]init ]; 
    //initialize child views 
    [self willRotateToInterfaceOrientation:0 duration:0];  

} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if ([model isLandscape]) { 
     self.view.frame = CGRectMake(0, 0, 1024, 768-80); 
    } 
    else { 
     self.view.frame = CGRectMake(0, 0, 768, 1024-80); 
    } 
    //rotate child views 
} 

我的代碼[模型isLandscape]的作品,所以我並不需要提供詳細資料,以它是如何工作的,但這裏有代碼反正:

- (bool)isLandscape { 
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
     return true; 
    else 
     return false; 
} 

-(id) init 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

- (void)orientationChanged:(NSNotification *)notification 
{ 
    UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation]; 
    if (curOrientation == UIDeviceOrientationPortrait || 
     curOrientation == UIDeviceOrientationPortraitUpsideDown || 
     curOrientation == UIDeviceOrientationLandscapeLeft || 
     curOrientation == UIDeviceOrientationLandscapeRight) 
    { 
     orientation = curOrientation; 
     ((AppDelegate*)([UIApplication sharedApplication].delegate)).savedOrientationForRestart = orientation; 
     NSLog(@"changed"); 
    } 
} 

-(void)validateOrientation { //first time when initializing orientation 
    UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation]; 
    if (curOrientation != UIDeviceOrientationPortrait && 
     curOrientation != UIDeviceOrientationPortraitUpsideDown && 
     curOrientation != UIDeviceOrientationLandscapeLeft && 
     curOrientation != UIDeviceOrientationLandscapeRight) 
    { 
     orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    } 

} 
+0

問題是什麼? – Bot

+0

請顯示一些代碼。你如何創建你的觀點? – sergio

+0

增加了更多評論 – user1307179

回答

0

OK 。所以原來在數十個背景和圖層中有些沒有正確旋轉到橫向/縱向...這是非常難以調試此問題...

最後,我連接了一個觸摸調試器,看看哪些視圖正在接受正確的觸摸,哪些不是...

非常有幫助! 只需在代碼中使用UIWindow子類而不是UIWindow,就可以工作。

#import <UIKit/UIKit.h> 
    @interface MyUIWindow : UIWindow { 
    } 

    -(void)rotate; 

    @end 

#import "MyUIWindow.h" 
    @implementation MyUIWindow 

    -(id) init{ 
     self = [super init]; 
     if(self) 
     { 
     } 
     return self; 
    } 

    - (void)sendEvent:(UIEvent *)event { 
     [super sendEvent:event]; 
     NSSet *touches = [event allTouches]; 
     if (touches.count != 1) 
      return; 
     UITouch *touch = touches.anyObject;  
     UIView * view = touch.view; 
     NSLog(NSStringFromClass([touch.view class])); //this prints out touch view 
    } 


    @end