Saturday, November 26, 2011

extern variable in iPhoneSDK 5.0

extern or global variable

Create a new project,

Create extern variable in the header class
extern NSString *myexternalString;

in the implementation file define it at the top
NSString *myexternalString;

Now extern variable is ready you can set the value and use it in any other class you just have to import the header before using it in other classes.


here is the sample code

Zooming UIImageView in iOS 5.0

Create a new project using xcode 4.0 with runtime iOS 5.0.

Suppose you have created view based project.

In root view controller class.

Add UIScrollView in xib and connect outlet to root ViewController.
Add UIImageView as subview on xib and connect its outlet to root ViewController OR create it writing code in root ViewController class and add subView to ScrollView.

Add UITapGestureRecognizer to UIImageView instance for single double taps and two finger touches.

set the UIScrollView's scale

// calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [scrollView frame].size.width / [imageView frame].size.width;
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = minimumScale;
scrollView.zoomScale = minimumScale;

//note set the imageView's frame in ViewwillAppear or ViewDidAppear.
imageView.frame = CGRectMake(0,0, 320, 480);

when tap occurs at imageView, calculate the rect and set the rect to scroll view.
[scrollView zoomToRect:zoomRect animated:YES];


here is the sample code