Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKieran Robinson
9,411 PointsPhoto Browser App - Extra Credit
I am trying to add the 'spring' spoken about in the video, however when i use this code UIAttachmentBehavior *attatch = [[UIAttachmentBehavior alloc]initWithItem:self.imageView attachedToAnchor:self.view.center]; [self.animator addBehavior:attatch];
to make the imageView 'spring' back to its original location, then add the behavior to the animator, the imageView is off the top right of the screen swinging strangely. This doesn't make sense as i have used [self.view.center] in order to centre the imageView?
3 Answers
Amit Bijlani
Treehouse Guest TeacherYour code is right but you just need to play with the other properties a bit. Also you might want to get rid of the snap behavior when apply the attachment behavior. Try the code below:
CGPoint midPoint = CGPointMake(CGRectGetMidY(self.view.bounds),CGRectGetMidY(self.view.bounds));
UIAttachmentBehavior *attach = [[UIAttachmentBehavior alloc]initWithItem:self.imageView attachedToAnchor:point];
attach.frequency = 0.9;
attach.damping = 0.1;
attach.length = 5;
[self.animator addBehavior:attach];
Feel free to play around with the values of the three properties: frequency, damping and length.
Stone Preston
42,016 Pointswhere is this code located? what are you trying to center it in? depending on where this code is, self.view might not be the view you want to use.
Kieran Robinson
9,411 PointsI have used the code in ViewWillAppear, is that the wrong place? Thanks for the reply!