3

我只是想了解使用 updateItemUsingCurrentState 的方式以及如何将缩放的 UIView 或 UIImageView 发送到动画师,这样我就可以在 viewDidLoad 上有一个大盒子和小盒子进行物理测试。我想学习如何将这些信息传递给它,以便稍后在其他事件中动态更改大小。

我看到 updateItemUsingCurrentState 是来自下面链接和苹果文档的答案,但没有很难的例子来获得规模工作。 带有 CGAffineTransform 的视图的 UIDynamicAnimator

我肯定会发现我需要稍后更改边界或其他东西,但现在我只想克服这个障碍。

@property (strong, nonatomic) IBOutlet UIView *CatBox;

@property (strong, nonatomic) IBOutlet UIImageView *catFishBox;
@property (nonatomic) UIDynamicAnimator* animator;

@property (strong, nonatomic) IBOutlet UIView *wrapperWolfBox;

@end

@implementation CatFishViewController

UIDynamicAnimator* _animator;
UIGravityBehavior* _gravity;
UICollisionBehavior* _collision;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    _gravity = [[UIGravityBehavior alloc] initWithItems:@[_wrapperWolfBox]];
    [_animator addBehavior:_gravity];

    _collision = [[UICollisionBehavior alloc]
                  initWithItems:@[_wrapperWolfBox]];
    _collision.translatesReferenceBoundsIntoBoundary = YES;
    [_animator addBehavior:_collision];
//
// 

    CGAffineTransform maybeGetTransform = CGAffineTransformScale(_wrapperWolfBox.transform, 2.2, 2.2);
    _wrapperWolfBox.transform = maybeGetTransform;


    [_animator updateItemUsingCurrentState:self.wrapperWolfBox];




//    _animator.updateItemUsingCurrentState:self.catFishBox;


}
4

1 回答 1

1

我在这里回答我自己的问题,因为互联网似乎没有问,所以我在某个地方错过了一些文档。

你不能使用仿射 他们只是不适合动画师。所以我发现你从动态中删除视图并更改“边界”或“框架”,然后将视图添加回动画师。

[_gravity removeItem:_wrapperWolfBox];
  CGRect frameZr = _wrapperWolfBox.bounds;
    frameZr.size.height += 60.0f;
    frameZr.size.width += 60.0f;
    _wrapperWolfBox.bounds = frameZr;
[_gravity addItem:_wrapperWolfBox];

这让我想到了下一个有趣的新问题和发现。规模是即时的。你可能想要,但我不想要。所以我会在一个新帖子中问这个问题。

享受!

于 2013-11-28T09:40:00.827 回答