- First we'll lay out the layout using Sizeclass:
@property (weaknonatomicIBOutletUIButton *bird;@property (strongnonatomic) IBOutletCollection(UIImageViewNSArray *ices;
For ice, because we have 4 blocks of ice here, so we're directly connected to an array.
- Lazy Loading a Uidynamicanimator
@property (strongnonatomic) UIDynamicAnimator *animator;- (UIDynamicAnimator *)animator{ if ( !_animator) { _animator = [UIDynamicAnimator new]; } return _animator;}
- Next, we give a listen to the bird's Click event
- (ibaction) Birdaction: (ID) sender{//Add gravity to birds and ice Nsmutablearray*TEMPARRM = [NsmutablearrayArray]; [Temparrm AddObject: Self. Bird]; [TEMPARRM Addobjectsfromarray: Self. Ices]; Uigravitybehavior *gravity = [[Uigravitybehavior alloc] INITWITHITEMS:TEMPARRM]; [ Self. AnimatorAddbehavior:gravity];//Add collisions to birds and iceUicollisionbehavior *collision = [[Uicollisionbehavior alloc] INITWITHITEMS:TEMPARRM]; [Collision Settranslatesreferenceboundsintoboundary:YES];//Add screen edge collisionsUibezierpath *path = [Uibezierpath bezierpathwithrect: Self. View. Bounds]; [Collision addboundarywithidentifier:@"Boundstest"Forpath:path]; [ Self. AnimatorAddbehavior:collision];/** uipushbehaviormodecontinuous, continuous force uipushbehaviormodeinstantaneous instantaneous force * * //Add thrust to the birdUipushbehavior *push = [[Uipushbehavior alloc] initwithitems:@[ Self. Bird] mode:uipushbehaviormodeinstantaneous];//direction of forcePush. Magnitude=5.0; Push. Angle=2* M_PI; [ Self. AnimatorAddbehavior:push];}
Look at the effect:
Can simply realize this little game, we can make the rest of the functions of their own perfect. Thank you
Lite version-Angry Birds