use*_*576 5 iphone animation view uiview
我使用Apple的示例应用程序中的代码并将其调整为我的.我想让UIImageView gameOverFalling运行这个方法(跌倒和反弹).它应该与UIView相冲突finalScoreView,正如你在第2行中看到的那样.
-(void)gameOverFallingMethod{
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:finalScoreView];
UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.gameOverFalling]];
[animator addBehavior:gravityBeahvior];
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.gameOverFalling]];
// Apple said: "Creates collision boundaries from the bounds of the dynamic animator's
// reference view (self.view)."
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
collisionBehavior.collisionDelegate = self;
[animator addBehavior:collisionBehavior];
self.animator = animator;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,它返回一个线程1:SIGABRT错误.在控制台中:
Run Code Online (Sandbox Code Playgroud)View item (<UIImageView: 0x10aaa0c70; frame = (15 175; 288 42); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10aa7e0a0>>) should be a descendant of reference view in <UIDynamicAnimator: 0x10ae17610> Stopped (0.000000s) in <UIView: 0x10aa9e1e0> {{0, 0}, {288, 195}}
当我用'self.view'替换第2行的'finalScoreView'时,它会工作,但它会落到整个屏幕的底部.
我做错了什么想法?我很想知道,谢谢!
从异常中看来,self.gameOverFalling它不会从finalScoreView视图层次结构中下降.请参阅UIDynamicAnimator类引用的引用:
要为视图设置动画,请使用initWithReferenceView:方法创建动画制作者.参考视图的坐标系用作动画师行为和项目的坐标系.与此类动画师关联的每个动态项必须是UIView对象,并且必须从参考视图下降.
| 归档时间: |
|
| 查看次数: |
4469 次 |
| 最近记录: |