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 trial

iOS

Custom Control

Hello,

So, I am working on building a custom control. I basically want to allow allow the application to generate rectangles (positioned at x = 0 with a variable y value that increases as each rectangle is added.) I would like them to respond to gestures where they have two positions (closed - which mostly hidden, open - expanded fully so that the entire rectangle is still visible but tethered to the side). I have already designed an application with this in mind. However, I do not know if using core graphics would be best or just the images that I have. If anyone can offer any advice that would be great. Thanks!

1 Answer

If you are going to have the rectangles animate I would highly recommend you use core graphics. Otherwise you'll end up having to render out several frames of the rectangle animating and set them as an image sequence like in the crystal ball app. There are even apps that will allow you to draw the shapes and it will generate code for you. Google PaintCode2, BezierCode and there is one other one that I can't remember.

Hey, thanks for the reply. Yeah, I have been tinkering around, using PaintCode2. I was wondering if it would be better to use CAShapeLayer. Since, I need the rectangle size to respond to a gesture recognizer, CAShapeLayer was suggested to me. However, I am having difficulty implementing the two in Xcode. I can draw a shape with CAShapeLayer, but having a seamless transition from being 1/3 the size to the full rectangle upon swiping is not something I'm finding easily in the documentation. I figured that I may have to animate it So, I am going to play around with that. My knowledge of CoreGraphics is lacking somewhat, so I am working on that now.

If you're doing that I think all you need to do is setup the animation code inside a method and then setup your gesture recognizer and pass in that method as the selector. If you already have some code you're working with that's not doing what you expect and you want me to take a look let me know. Otherwise you can checkout this file that's part of one of my projects. There are 2 gesture recognizers in there and as you can see I have methods that hold all the logic and they just get called when that gesture is performed.