我有一个UIViewController容器,其中包含多个UIViewController框。我想使用UIKit动力学将物理行为应用到盒中。容器定义外部边框。

UIDynamicAnimator是容器中的一个对象,所有的动态行为都是盒子的一部分。
问题:当我从框(子视图控制器)中引用动画器来添加框行为时,我会遇到错误消息。
这是错误信息
> Terminating app due to uncaught exception
> 'NSInvalidArgumentException', reason: 'View item (<UIView: 0x9972720;
> frame = (0 568; 120 40); clipsToBounds = YES; autoresize = W+H;
> gestureRecognizers = <NSArray: 0x9976f80>; layer = <CALayer:
> 0x9972780>>) should be a descendant of reference view in
> <UIDynamicAnimator: 0x9906d40> Stopped (0.000000s) in <UIView:
> 0x9916bf0> {{0, 0}, {320, 568}}'UIViewController容器
- (void)viewDidLoad
{
[super viewDidLoad];
UIDynamicAnimator* animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
_animator = animator;
...
}添加框作为子视图和ChildViewControllers
- (void)tapOnContainer:(UITapGestureRecognizer*)touch {
...
BoxViewController *note = [[BoxViewController alloc]init];
[box setContainerObject:self];
[self addChildViewController:box];
[self.view addSubview:box.view];
}UIViewController Box
- (void)viewDidLoad
{
_containerViewController = (ViewController*) self.parentViewController;
_gravityBehaviour = [[UIGravityBehavior alloc]initWithItems:@[self.view]];
[_containerViewController.animator addBehavior:_gravityBehaviour];
...
}知道该怎么做吗?这样拆分UIDynamicAnimator和UIDynamicBehavior对象可以吗?
发布于 2013-12-19 18:15:53
在这一行:
_gravityBehaviour = [[UIGravityBehavior alloc]initWithItems:@[self.view]];
添加您的小视图而不是self.view。
https://stackoverflow.com/questions/19549144
复制相似问题