There are 3 behaviors in my method,i am pretty sure animationOptions is the one causing bug.AnimationOptions is only used to ban rotation.If i delete this behavior,my code work fine.
Here is my bug.Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil’
After i add a exception breakpoint,the breakpoint stay at this line:
[self addChildBehavior:self.animationOptions];
If i delete this line,my code work fine.
But how can i fix this bug,i can not find where is this line mistake
Here is my DropitBehavior.m
#import "DropitBehavior.h"
@interface DropitBehavior()
@property(strong,nonatomic) UIGravityBehavior *gravity;
@property(strong,nonatomic) UICollisionBehavior *collider;
@property(strong,nonatomic) UIDynamicItemBehavior *animationOptions;
@end
@implementation DropitBehavior
-(UIGravityBehavior *)gravity
{
if (!_gravity) {
_gravity=[[UIGravityBehavior alloc]init];
_gravity.magnitude=0.90;
}
return _gravity;
}
-(UICollisionBehavior *)collider
{
if (!_collider) {
_collider=[[UICollisionBehavior alloc]init];
_collider.translatesReferenceBoundsIntoBoundary=YES;
}
return _collider;
}
-(UIDynamicItemBehavior *)animationOptions
{
if (_animationOptions) {
_animationOptions=[[UIDynamicItemBehavior alloc]init];
_animationOptions.allowsRotation=NO;
}
return _animationOptions;
}
-(void)additem:(id <UIDynamicItem>)item
{
[self.gravity addItem:item];
[self.collider addItem:item];
[self.animationOptions addItem:item];
}
-(void)removeitem:(id <UIDynamicItem>)item
{
[self.gravity removeItem:item];
[self.collider removeItem:item];
[self.animationOptions removeItem:item];
}
-(instancetype)init
{
self=[super init];
[self addChildBehavior:self.gravity];
[self addChildBehavior:self.collider];
[self addChildBehavior:self.animationOptions];
return self;
}
@end
Aucun commentaire:
Enregistrer un commentaire