2014-10-08 26 views
4

所以我想旋轉我的UIView,看起來像3D。我做了一個快速搜索,互聯網上說:使用核心動畫。所以,我接過來一看,看到和我想出了這個代碼,以我的觀點旋轉使用CABasicAnimation切割查看一半

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"]; 
    animation.fromValue = @(0); 
    animation.toValue = @(4 * M_PI); 
    animation.repeatCount = INFINITY; 
    animation.duration = 5.0; 

    [self.layer addAnimation:animation forKey:@"rotation"]; 

    CATransform3D transform = CATransform3DIdentity; 
    transform.m34 = 1.0/-2000; 

    self.layer.transform = transform; 

    self.layer.masksToBounds = NO; 

實際視圖旋轉很好,但它切斷一半的看法。下面是我在Photoshop中製作的快照,以展示我的意思enter image description here

我已經做了幾個小時的搜索,現在我似乎無法弄清楚是什麼導致了這種情況。任何幫助或意見,將不勝感激。謝謝。

編輯:我怎麼繼承人創建的視圖:

UIView* test = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)]; 
     test.backgroundColor = [UIColor redColor]; 
     [self.view addSubview:test]; 

嘗試它在界面生成器做了一個視圖後,它工作正常,但我需要讓這些編程。

+0

您的代碼工作正常,我。紅色視圖如何創建並添加到其超級視圖。它的超級觀點是否有限制? – rdelmar 2014-10-09 00:16:36

+0

@rdelmar他們只是添加了[addSubview]到superview中,沒有任何限制或任何事情發生。 – BlueSpud 2014-10-09 00:22:02

+0

由於你的代碼爲我工作(與故事板添加子視圖),你應該顯示你是如何創建和添加紅色視圖。我不認爲問題出在動畫代碼上。 – rdelmar 2014-10-09 00:25:36

回答