UIDynamicAnimator - 不会UIView的工作,但将与Self.View? [英] UIDynamicAnimator - won't work with UIView but will with Self.View?

查看:268
本文介绍了UIDynamicAnimator - 不会UIView的工作,但将与Self.View?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用苹果的示例应用程序这个code和它调整到我的。我想要的UIImageView gameOverFalling 运行此方法(反弹的下跌及实物为准)。它应该与UIView的 finalScoreView 碰撞,你可以在网上看到2

   - (无效){gameOverFallingMethod
    UIDynamicAnimator *动画= [[UIDynamicAnimator页头​​] initWithReferenceView:finalScoreView];    UIGravityBehavior * gravityBeahvior = [[UIGravityBehavior页头] initWithItems:@ self.gameOverFalling]];
    [动画addBehavior给:gravityBeahvior];    UICollisionBehavior * collisionBehavior = [[UICollisionBehavior页头] initWithItems:@ self.gameOverFalling]];
    //苹果说:从创建动态动画的的边界碰撞边界
    //引用视图(self.view)。
    collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
    collisionBehavior.collisionDelegate =自我;
    [动画addBehavior给:collisionBehavior];    self.animator =动画师;
}

然而,当我跑我的应用程序,它返回一个线程1:SIGABRT错误。在控制台:


 查看项目(小于的UIImageView:0x10aaa0c70;帧=(15 175 288 42);
  AUTORESIZE = RM + BM; userInteractionEnabled = NO;层= LT; CALayer的:0x10aa7e0a0​​>>)
应该是参考视图中的后裔< UIDynamicAnimator:0x10ae17610>
停止(0.000000s)上述<的UIView:0x10aa9e1e0> {{0,0},{288,195}}


它工作时,我代替'finalScoreView'与'self.view'2号线,但随后下降到整个屏幕的底部。

任何想法,我做错了什么?我很想知道,谢谢!


解决方案

这似乎从异常 self.gameOverFalling 不会从 finalScoreView下降在您的视图层次。请参阅从报价<一个href=\"https://developer.apple.com/library/ios/documentation/uikit/reference/UIDynamicAnimator_Class/Reference/Reference.html\">UIDynamicAnimator类引用:


  

要动画视图,创建具有initWithReferenceView一个漫画家:
  方法。参考视图的坐标系作为
  协调动画师的行为和物品系统。每个动态
  你这种动画的关联项目必须是一个UIView对象
  必须从下降的参考图。


I used this code from Apple's sample app and adjusted it to mine. I want the UIImageView gameOverFalling to run this method (fall and kind of bounce). It should collide with the UIView finalScoreView, as you can see in line 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;
}

However when I run my app, it returns a Thread 1: SIGABRT error. In the console:

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}}

It works when I replace 'finalScoreView' on line 2 with 'self.view', but then it falls to the bottom of the whole screen.

Any ideas what I did wrong? I would love to know, thanks!

解决方案

It appears from the exception that self.gameOverFalling does not descend from finalScoreView in your view hierarchy. See the quote from UIDynamicAnimator class reference:

To animate views, create an animator with the initWithReferenceView: method. The coordinate system of the reference view serves as the coordinate system for the animator’s behaviors and items. Each dynamic item you associate with this sort of animator must be a UIView object and must descend from the reference view.

这篇关于UIDynamicAnimator - 不会UIView的工作,但将与Self.View?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆