In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how ios rotates pictures through rotating gestures. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it.
Example: rotate a picture by rotating a gesture
This example will improve the previous example by adding a rotation gesture processor based on the previous example, so that the application can not only scale the picture according to the user kneading gesture, but also rotate the picture according to the user rotation gesture.
Copy the above application and rename it RotateImage. The rest of the application basically does not need to be modified, just slightly modify the implementation part of the controller class, add a rotation gesture processor to the UIImageView control, and let the program rotate the picture according to the Radian of the gesture rotation. The following is the implementation code for the modified controller class.
Program list: codes/01/1.3/RotateImage/RotateImage/FKViewController.m
@ implementation FKViewController
UIImage* srcImage
CGFloat currentScale
CGFloat currentRotation
-(void) viewDidLoad
{
[superviewDidLoad]
[UIApplication sharedApplication] .statusBarHidden = YES
SrcImage= [UIImage paired picture picpathNAMD @ "seashore.png"]
/ / set the picture to be displayed directly in the middle (without any zooming)
Self.view.contentMode = UIViewContentModeCenter
/ / set the picture initially displayed by p_w_picpathView
Self.p_w_picpathView.p_w_picpath = srcImage
/ / set the initial scale
CurrentScale = 1
CurrentRotation = 0
/ / set p_w_picpathView to allow user interaction and support multi-touch
Self.p_w_picpathView.userInteractionEnabled = YES
Self.p_w_picpathView.multipleTouchEnabled = YES
/ / create a UIPinchGestureRecognizer gesture processor that fires scaleImage: method
UIPinchGestureRecognizer* gesture = [[UIPinchGestureRecognizer alloc]
InitWithTarget:self action:@selector (scaleImage:)]
/ / add a gesture processor for p_w_picpathView
[self.p_w_picpathView addGestureRecognizer:gesture]
/ / create a UIRotationGestureRecognizer gesture processor that fires rotateImage: method
UIRotationGestureRecognizer* rotateGesture=
[[UIRotationGestureRecognizer alloc]
InitWithTarget:selfaction:@selector (rotateImage:)]
/ / add a gesture processor for p_w_picpathView
[self.p_w_picpathViewaddGestureRecognizer:rotateGesture]
}
-(void) scaleImage: (UIPinchGestureRecognizer*) gesture
{
CGFloatscale = gesture.scale
/ / calculate the scaled target image size according to the zoom ratio of the gesture processor
CGSizetargetSize = CGSizeMake (srcImage.size.width * scale * currentScale
SrcImage.size.height * scale * currentScale)
/ / A pair of pictures are scaled and rotated
Self.p_w_picpathView.p_w_picpath = [[srcImage p_w_picpathByScalingToSize:targetSize]
P_w_picpathRotatedByRadians:currentRotation]
/ / if the gesture ends
If (gesture.state = = UIGestureRecognizerStateEnded)
{
/ / calculate the zoom ratio of the picture at the end
CurrentScale = scale * currentScale
}
}
-(void) rotateImage: (UIRotationGestureRecognizer*) gesture
{
/ / get the Radian of gesture rotation
CGFloatrotation = gesture.rotation
/ / calculate the size of the scaled target picture according to the current zoom ratio
CGSizetargetSize = CGSizeMake (srcImage.size.width * currentScale
SrcImage.size.height * currentScale)
/ / A pair of pictures are scaled and rotated
Self.p_w_picpathView.p_w_picpath = [[srcImage p_w_picpathByScalingToSize:targetSize]
P_w_picpathRotatedByRadians:currentRotation + rotation]
/ / if the rotation gesture ends
If (gesture.state = = UIGestureRecognizerStateEnded)
{
CurrentRotation = currentRotation + rotation
}
}
@ end
The bold code in the above program adds a UIRotationGestureRecognizer gesture processor to the UIImageView control. When the gesture processor detects the rotation gesture, it will activate the controller's rotateImage: method, which will rotate the picture according to the Radian of the gesture rotation (the program also uses the UIImage+FKCategory method to rotate the picture).
The above is all the content of the article "how ios rotates pictures by rotating gestures". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.