Silver Challenge: Pinch to Zoom

Add pinch-to-zoom to the Hypnosister project from Chapter 5.

The first step is to give the scroll view a delegate:

  • BNRAppDelegate should conform to the UIScrollViewDelegate protocol.

  • In application:didFinishLaunchingWithOptions:, set the scroll view’s delegate property.

To perform as the scroll view’s delegate, BNRAppDelegate will need a property that points to the instance of BNRHypnosisView. Add this property in a class extension in BNRAppDelegate.m and update the rest of the code to use the property instead of the BNRHypnosisView local variable.

To set up the scroll view, you will need to give it one BNRHypnosisView as a subview and turn off the paging. The scroll view also needs limits on how much it can zoom in and out. Find the relevant UIScrollView properties to set in this class’s reference page in the documentation.

Finally, you will need to implement the scroll view delegate method viewForZoomingInScrollView: to return the BNRHypnosisView.

If you get stuck, visit the reference pages for the UIScrollView class and for the UIScrollViewDelegate protocol.

To simulate two fingers in the simulator to test your zooming, hold down the Option key while using the mouse.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset