Hi Forum,
I had the idea that I would make a class of ZoomView that would hold a .xib file containing buttons, text, images etc... that I want to scroll and zoom on. In doing some test code, I find very erratic behavior from viewForZoomingInScrollView: in the code below. It jumps, runs around the page and then when I let go, will no longer scroll.
This is a 'Blank' application and in the AppDelegate file for testing right now:
AppDelegate.h
Code:
@class ZoomView; // custom class with .xib file
@interface AppDelegate : UIResponder <UIApplicationDelegate, UIScrollViewDelegate> {
UIView *innerview;
ZoomView *zoomView;
}
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor blueColor];
innerview = [[UIView alloc] initWithFrame:CGRectZero];
zoomView = [[ZoomView alloc] initWithNibName:@"ZoomView" bundle:nil];
[innerview addSubview:zoomView.view];
CGRect aframe = CGRectMake(0, 100, 320, 200);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:aframe];
scrollView.contentSize = CGSizeMake(600, 400);
scrollView.backgroundColor = [UIColor greenColor];
scrollView.maximumZoomScale = 2;
scrollView.minimumZoomScale = 0.25;
scrollView.scrollEnabled = YES;
scrollView.scrollsToTop = NO;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
scrollView.delegate = self;
[scrollView addSubview:innerview];
[self.window addSubview:scrollView];
[self.window makeKeyAndVisible];
return YES;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
// NSLog(@"viewForZoomingInScrollView:");
return innerview;
}
Should I be using a pinchGestureRecognizer instead? I just thought that this would be easier.
Does anyone have a good tutorial on the pinchGestureRecognizer for 4.2? I see in the objects > Gesture Recognizers that you can drag one of these onto your .xib file but, no idea how to hook it up from there. Any help would be greatly appreciated.
Thanks
kmt