Graphics Programs Reference
In-Depth Information
To zoom, you must implement the method viewForZoomingInScrollView: in the
UIScrollView 's delegate . This method returns the instance of the view to zoom in
on. The view will be the instance of HypnosisView , and the UIScrollView 's del-
egate will be the HypnosisterAppDelegate .
Currently, HypnosisterAppDelegate has a pointer to HypnosisView in a local
variable in application:didFinishLaunchingWithOptions: . However, to
zoom, HypnosisterAppDelegate will need access to that view in another method -
viewForZoomingInScrollView: . This means HypnosisterAppDelegate
needs an instance variable that points to a HypnosisView instead of a local variable. In
HypnosisterAppDelegate.h , declare that HypnosisterAppDelegate con-
forms to UIScrollViewDelegate and declare an instance variable to hold the Hyp-
nosisView .
#import <UIKit/UIKit.h>
// Don't forget this import statement!
#import "HypnosisView.h"
@interface HypnosisterAppDelegate : UIResponder
<UIApplicationDelegate , UIScrollViewDelegate >
{
HypnosisView *view;
}
@property (strong, nonatomic) UIWindow *window;
@end
Now, in HypnosisterAppDelegate.m , put the HypnosisView into the instance
variable instead of a local variable.
HypnosisView *view = [[HypnosisView alloc] initWithFrame:screenRect];
view = [[HypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:view];
Finally, implement viewForZoomingInScrollView: in HypnosisterAp-
pDelegate.m to return this view.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return view;
}
Build and run the application. Pinch and pull with two fingers to zoom in and out. (On the
simulator, you can simulate two fingers by holding down the Option key, clicking, and
then moving the mouse.) Pan with one finger to scroll once you have zoomed in.
Search WWH ::




Custom Search