去除進入CALayer的世界後,造成動畫:CALayer的幀值甚至superlayer
我創建需要保持在視圖中,無論設備方向的層。有人可以告訴我爲什麼我的圖層在旋轉之後從舊位置開始動畫,即使我將它從超級圖層中移除了?我知道frame和borderWidth屬性是動畫的,但它們是否可以從superLayer中移除後生成動畫?
如果從superLayer中刪除不會重置圖層屬性,因爲圖層對象還沒有被釋放(好吧,我可以理解這一點),我該如何模仿新顯示的圖層的行爲,以便邊框不會顯示像它在旋轉之後從舊位置移動。
我創建了這個示例項目 - 剪切和粘貼,如果你願意。你只需要鏈接石英核心庫。
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController()
@property (nonatomic,strong) CALayer *layerThatKeepAnimating;
@end
@implementation ViewController
-(CALayer*) layerThatKeepAnimating
{
if(!_layerThatKeepAnimating)
{
_layerThatKeepAnimating=[CALayer layer];
_layerThatKeepAnimating.borderWidth=2;
}
return _layerThatKeepAnimating;
}
-(void) viewDidAppear:(BOOL)animate
{
self.layerThatKeepAnimating.frame=CGRectMake(self.view.bounds.size.width/2-50,self.view.bounds.size.height/2-50, 100, 100);
[self.view.layer addSublayer:self.layerThatKeepAnimating];
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.layerThatKeepAnimating removeFromSuperlayer];
}
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.layerThatKeepAnimating.frame=CGRectMake(self.view.bounds.size.width/2-50,self.view.bounds.size.height/2-50, 100, 100);
[self.view.layer addSublayer:self.layerThatKeepAnimating];
}
@end
[移動CALayers時禁用動畫]的可能重複(http://stackoverflow.com/questions/2930166/disable-animation-when-moving-calayers) – jrturton 2013-02-24 16:39:31
該鏈接接受的答案(雖然我」 d使用setDisablesActions)將會做你需要的。 – jrturton 2013-02-24 16:40:14
@ jrturton,這不是重複的。在另一個鏈接和你的兩個答案都屬於CATransaction。我沒有在這裏使用它。 – Spectravideo328 2013-02-24 16:44:35