To add zooming, you need to give the scroll view a delegate. In HypnosisterAppDelegate.h, declare that HypnosisterAppDelegate conforms to the UIScrollViewDelegate protocol:
@interface HypnosisterAppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate>
Open HypnosisterAppDelegate.m. In application:didFinishLaunchingWithOptions:, set the delegate and the limits of the zoom:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CGRect wholeWindow = [[self window] bounds]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:wholeWindow]; [[self window] addSubview:scrollView]; // Make your view twice as large as the window CGRect reallyBigRect; reallyBigRect.origin = CGPointZero; reallyBigRect.size.width = wholeWindow.size.width * 2.0; reallyBigRect.size.height = wholeWindow.size.height * 2.0; [scrollView setContentSize:reallyBigRect.size]; // Center it in the scroll view CGPoint offset; offset.x = wholeWindow.size.width * 0.5; offset.y = wholeWindow.size.height * 0.5; [scrollView setContentOffset:offset]; // Enable zooming [scrollView setMinimumZoomScale:0.5]; [scrollView setMaximumZoomScale:5]; [scrollView setDelegate:self]; // Create the view view = [[HypnosisView alloc] initWithFrame:reallyBigRect]; [view setBackgroundColor:[UIColor clearColor]]; [scrollView addSubview:view]; [scrollView release]; [[self window] makeKeyAndVisible]; return YES; }
In that same file, implement the delegate method viewForZoomingInScrollView: that tells the scroll view which view to transform.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return view; }
Build and run the application and zoom away! (In the simulator, use the Option key to simulate two finger touches.)
3.21.248.162