It's a little late today, so we've been waiting. Haha, today's fun come again, we come to play a play, how to put a picture, rotating zoom plus move. Look forward to it, then without further ado us to achieve them.
Speaking of these features, the implementation in iOS is nothing more than a gesture touch function, plus a calculated offset to calculate the coordinates. It's OK. It's very simple.
We're building a new project.
#import "ViewController.h"
@interface viewcontroller () <uigesturerecognizerdelegate>
{
uiimageview *_imageview;
}
@end
@implementation Viewcontroller
-(void) viewdidload {
[superviewdidload];
[selfcreateimageview];
[selfcreatepinchgesture];
[selfcreaterotataegesture];
[Self createpangesture];
}
// Create a zoom gesture
-(void) createpinchgesture
{
uipinchgesturerecognizer *pinchges =[[ uipinchgesturerecognizer Alloc]init];
pinchges. Delegate = Self ;
[pinchges addTarget:selfAction:@selector (pinchges:)];
[_imageviewaddgesturerecognizer:p inchges];
}
-(void) pinchges: ( Uipinchgesturerecognizer *) Ges
{
// ratio column
cgfloat scale = Ges. Scale ;
// change View Billy
Ges. View . Transform = Cgaffinetransformscale (GES. View . Transform , scale, scale);
// ratio listed as 1
Ges. Scale = 1 ;
}
Create a rotation gesture
-(void) createrotataegesture
{
uirotationgesturerecognizer *rotationges = [[Uirotationgesturerecognizer alloc] init];
rotationges. Delegate = Self ;
[rotationges addTarget:selfAction:@ Selector(rotges:)];
[_imageviewaddgesturerecognizer: rotationges];
}
-(void) rotges: ( Uirotationgesturerecognizer *) Ges
{
Ges. View . Transform = cgaffinetransformrotate (GES. View . Transform , Ges. Rotation );
Ges. Rotation = 0 ;
}
-(void) Createimageview
{
uiimageview *imageview = [[uiimageviewalloc] Init ];
ImageView. Frame = CGRectMake ( a);
ImageView. Image = [UIImageimagenamed:@ "Webwxgetmsgimg.jpg" ];
ImageView. userinteractionenabled = YES ;
[self. View addsubview: ImageView];
_imageview = ImageView;
}
// Calculate offset Move picture
// The first method of calculation
-(void) touchesmoved: ( Nsset *) touches withevent: (uievent *) Event
{
[Selfclass] cancelpreviousperformrequestswithtarget :self];
// fetch to current touch object
uitouch *touch = [touchesanyobject];
// Current position
cgpoint point = [Touchlocationinview:self. View ];
// Previous location
cgpoint prepoint = [Touchpreviouslocationinview:self. View ];
// calculate the offset of two clicks
cgpoint trans =cgpointmake(point. x -Prepoint. x , point. y -Prepoint. y );
// modify The structure ofthe ImageView ( The center point of the ImageView is assigned to Center , is the change of coordinates)
cgpoint Center =_imageview. Center ;
// The calculated offset is the x -axis of the imagview plus the offset as calculated, as y the axis does not change, that is 0 , do not add
_imageview. Center = Cgpointmake (center. x + trans. x , center. y + trans. y );
// This is a click event, because all have been accurately calculated, each with a precise offset so there is no need to clean up the last offset
}
// Section 2 method of calculation
-(void) createpangesture
//{
Uipangesturerecognizer *pangse = [[Uipangesturerecognizer alloc]init];
//
Pangse.delegate = self;
//
[Pangse addtarget:self Action: @selector (panGes1:)];
[_imageview Addgesturerecognizer:pangse];
//}
-(void) PanGes1: (Uipangesturerecognizer *) ges
//{
Cgpoint point = [Ges TranslationInView:ges.view];
//
Ges.view.transform = Cgaffinetransformtranslate (Ges.view.transform, Point.x, POINT.Y);
//
// // Offset Clear 0 ( This thing gesture, if each gesture call does not clean up will automatically accumulate to the next, resulting in inaccurate, so each time to clean up the last offset, recalculate the next time, to ensure accurate ) this has not been accurately calculated.
//// is to return to the original position, and then the new calculation, or will accumulate until next time
[Ges Settranslation:cgpointzero InView:ges.view];
//
//
//}
// in conjunction with other gestures
-(BOOL) Gesturerecognizer: ( Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer
{
returnYES;
}
@end
Yes, this is the son, haha. Today, the end of the year 30 rest, (in advance) will not be more, I wish you a good year.
iOS picture rotation zoom plus move