CALayer の世界へ:
デバイスの向きに関係なく、ビューの中央に留まる必要があるレイヤーを作成しています。スーパーレイヤーからレイヤーを削除したにもかかわらず、古い位置からの回転後にレイヤーがアニメーション化されるのはなぜですか? frame および borderWidth プロパティがアニメーション化可能であることは理解していますが、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