2011-07-07 17 views
0

我使用下面的代碼來查找被按下的圖層。從不同方向的觸摸位置查找CALayer?

- (CALayer *)layerForTouch:(UITouch *)touch { 
    UIView *view = self.view; 

    CGPoint location = [touch locationInView:view]; 
    location = [view convertPoint:location toView:nil]; 

    CALayer *hitPresentationLayer = [view.layer.presentationLayer hitTest:location]; 
    if (hitPresentationLayer) { 
     return hitPresentationLayer.modelLayer; 
    } 

    return nil; 
} 

一切正常,我正常肖像模式。

問題是,如果我旋轉視圖,所以我在景觀和按屏幕頂部中間位置將返回313,543。X值應爲0,因爲它是橫向模式的屏幕頂部但它看起來像這樣的代碼不重製接觸點取決於用戶目前在什麼方向。

任何想法如何獲得真正的接觸點取決於方向?

回答

1

我曾在一個酥料餅類似的問題,我刪除了行:

location = [view convertPoint:location toView:nil]; 

,並適當地爲我工作。