Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
November 24, 2017, 10:42:13 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: viewForZoomingInScrollView or pinchGesture?  (Read 1783 times)
kt
Newbie
*
Posts: 4


« on: December 01, 2011, 10:29:49 AM »

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: (Objective-C)
@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: (Objective-C)
- (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
kt
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.