2012-09-01 80 views
1

我正在開發我的第一款iPhone遊戲並且遇到此問題。座標系似乎沒有了,很可能我做錯了什麼。iOS座標系超出範圍

我有一個UIViewController,它被設置爲RootViewController。之後,viewController調用UIView;

應用程序委託;

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
MyViewController *myViewController = [[MyViewController alloc] init]; 
[[self window] setRootViewController:myViewController]; 

ViewController;

CGRect frame = [[UIScreen mainScreen] bounds]; 
MyView *v = [[MyView alloc] initWithFrame:frame]; 
[self setView:v]; 

查看;

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
. 
. 
. 
[myCALayer setBounds:CGRectMake(0.0, 0.0, width, height)]; 
[myCALayer setPosition:CGPointMake(x, y)]; 

所以0.0假設是左上角,但在我的開發環境,它是出了可視屏幕的一側,還是地方的左上方,但是當我0.0繪製圖像,我只能看到它的右下角的一小部分。

任何想法爲什麼發生這種情況?

+0

什麼是寬度,高度,x和y?你在哪裏定義這些? – rdelmar

+0

寬度:48,高度:70,x:2,y:10.我在視圖中定義這些。 –

回答

0

位置

指定接收方的superlayer的座標系中的位置。動畫。

@property CGPoint position 

討論

的位置是相對於anchorPoint。此屬性的值以點指定。默認值是(0.0,0.0)。

用於在boundsanchorPointposition性能之間的關係的詳細信息參見「Layer Geometry and Transforms」Core Animation Programming Guide

默認情況下,anchorPoint設置爲(0.5,0.5)它是圖層的中心,所以如果將圖層的位置設置爲(0,0),圖層的中心將位於(0,0) - 僅右下角角將可見,您需要將anchorPoint設置爲(0,0),然後將位置設置爲(0,0)。

+0

謝謝!鏈接「Layer Geometry and Transforms」指出我正確的方向,並且CALayer的anchorPoint是解決我的問題的正確猜測。我的觀點顯然沒有問題。 myCALayer.anchorPoint = CGPointMake(0,0);完全解決了這個問題。 –