12

私はUIView影と UIImageView サブビューを持っています。

iPad が回転したときにビューのサイズを変更したいのですが、willRotateToInterfaceOrientationコールバックでこれを実行しようとしています。

基本的な方法で影を設定するとUIView、回転が非常に不安定になります。だから、影の設定layer.shadowPathを設定する方法について、他の人からいくつかの提案が欲しいです。

同じブロックで[UIView animateWithDuration:animations]新しいものを使用して設定し、フレーム サイズの変更をアニメーション化しようとしましたが、シャドウ パスは新しいサイズにスナップします。shadowPath

そして、アニメーション ブロックでレイヤーの shadowPath を変更しないと、変更されません。

私が行ったいくつかの検索から、レイヤー プロパティへの変更をアニメートするには、CABasicAnimation.

ですから、「UIView のフレーム サイズとレイヤーの変更を同時にアニメーション化するにはどうすればよいですか?」という疑問があると思います。

4

1 に答える 1

8

期待するよりも少し多くのコードがありますが、このようなものはうまくいくはずです。

  CGFloat animationDuration = 5.0;

  // Create the CABasicAnimation for the shadow
  CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"];
  shadowAnimation.duration = animationDuration;
  shadowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // Match the easing of the UIView block animation
  shadowAnimation.fromValue = (id)self.shadowedView.layer.shadowPath;

  // Animate the frame change on the view
  [UIView animateWithDuration:animationDuration
                        delay:0.0f
                      options:UIViewAnimationCurveEaseInOut
                   animations:^{
                     self.shadowedView.frame = CGRectMake(self.shadowedView.frame.origin.x,
                                                          self.shadowedView.frame.origin.y,
                                                          self.shadowedView.frame.size.width * 2.,
                                                          self.shadowedView.frame.size.height * 2);
                   } completion:nil];

  // Set the toValue for the animation to the new frame of the view
  shadowAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath;

  // Add the shadow path animation
  [self.shadowedView.layer addAnimation:shadowAnimation forKey:@"shadowPath"];

  // Set the new shadow path
  self.shadowedView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath;
于 2012-08-08T00:57:52.370 に答える