In the APPDELEGATE.M file, create the View controller
#import "MAYAppDelegate.h"
#import "MAYViewController.h"
@implementation Mayappdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
Override point for customization after application launch.
Mayviewcontroller *root = [[Mayviewcontroller alloc] init];
Self.window.rootViewController = root;
[Root release];
Self.window.backgroundColor = [Uicolor Whitecolor];
[Self.window makekeyandvisible];
return YES;
}
Create a View controller Mayviewcontroller, in the View controller mayviewcontroller.m file, create a view
#import "MAYViewController.h"
#import "TOUCH.H"
@interface Mayviewcontroller ()
@end
@implementation Mayviewcontroller
-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil
{
self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];
if (self) {
Custom initialization
}
return self;
}
-(void) viewdidload
{
[Super Viewdidload];
Do any additional setup after loading the view.
Self.view.backgroundColor = [Uicolor Lightgraycolor];
Touch *touch = [[Touch alloc] Initwithframe:cgrectmake (50, 150, 200, 200)];
Touch.backgroundcolor = [Uicolor Greencolor];
[Self.view Addsubview:touch];
[Touch release];
}
Create a new view class touch, add on the view controller, implement the Zoom function in the TOUCH.M file
#import "TOUCH.H"
@implementation Touch
-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Initialization code
Set whether multi-touch is supported (yes support, no not supported)
self.multipletouchenabled = YES;
}
return self;
}
Calculate the distance between two points
-(CGFloat) Distance: (cgpoint) point1 Point2: (cgpoint) Point2
{
CGFloat dx = point1.x-point2.x;
CGFloat dy = point1.y-point2.y;
CGFloat tance = sqrt (Pow (DX, 2) + pow (dy, 2));
return tance;
}
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event
{
if (1 = = [touches count]) {
Return
}
Set Touch points
Nsarray *array = [touches allobjects];
Uitouch *touch1 = [array firstobject];
Uitouch *TOUCH2 = [array lastobject];
Get the touch point before moving
Cgpoint firstpreviouspoint = [Touch1 previouslocationinview:self];
Cgpoint secondpreviouspoint = [Touch2 previouslocationinview:self];
Gets and moves the touch point after
Cgpoint firstcurrentpoint = [Touch1 locationinview:self];
Cgpoint secondcurrentpoint = [Touch2 locationinview:self];
Gets the distance between the two points before and after the move
CGFloat previousdistance = [self distance:firstpreviouspoint point2:secondpreviouspoint];
CGFloat currentdistance = [self distance:firstcurrentpoint point2:secondcurrentpoint];
Get zoom ratio
CGFloat scanl = currentdistance/previousdistance;
Get the Zoomed view size
Self.bounds = CGRectMake (0, 0, self.bounds.size.width * scanl, Self.bounds.size.height * scanl);
}
Zoom (IOS) for views with two touch points