IOS: transform attribute of UIView and implementation of drag-and-drop view, uiviewtransform

Source: Internet
Author: User

IOS: transform attribute of UIView and implementation of drag-and-drop view, uiviewtransform
1. Use of the transform attribute of UIView

# Import "ViewController. h "@ interface ViewController () @ property (weak, nonatomic) IBOutletUIImageView * imageV; @ end @ implementation ViewController-(void) viewDidLoad {[superviewDidLoad];}-(IBAction) moveUp :( id) sender {// translation [UIView animateWithDuration: 0.5 animations: ^ {// use Make, which is a deformation relative to the original position. // self. imageV. transform = CGAffineTransformMakeTranslation (0,-100); // deformation relative to the previous one. self. imageV. transform = CGAffineTransformTranslate (self. imageV. transform, 0,-100);}];}-(IBAction) moveDown :( id) sender {// translation [UIView animateWithDuration: 0.5 animations: ^ {// use Make, it is a deformation relative to the original location. // self. imageV. transform = CGAffineTransformMakeTranslation (0,-100); // deformation relative to the previous one. self. imageV. transform = CGAffineTransformTranslate (self. imageV. transform, 0,100) ;}] ;}- (IBAction) rotation :( id) sender {[UIViewanimateWithDuration: 0.5 animations: ^ {// rotation (rotation degree, which is a radian) // self. imageV. transform = CGAffineTransformMakeRotation (M_PI_4); self. imageV. transform = CGAffineTransformRotate (self. imageV. transform, M_PI_4);}];}-(IBAction) scale :( id) sender {[UIView animateWithDuration: 0.5 animations: ^ {// zoom // self. imageV. transform = CGAffineTransformMakeScale (0.5, 0.5); self. imageV. transform = CGAffineTransformScale (self. imageV. transform, 0.8, 0.8) ;}] ;}@ end

2. simple use of the touch method of UIView to achieve the effect of dragging a view
# Import "RedView. h" @ implementation RedView // call-(void) touchesBegan :( NSSet
 
  
*) Touches withEvent :( UIEvent *) event {NSLog (@ "% s" ,__ func _);} // call when the touch starts to move (it will be called continuously during movement) // NSSet: unordered // NSArray: ordered-(void) touchesMoved :( NSSet
  
   
*) Touches withEvent :( UIEvent *) event {// NSLog (@ "% s" ,__ func _); // drag and drop UITouch * touch = [touches anyObject] In UIView; // calculate the offset = X CGPoint curP = [touch locationInView: self]; CGPoint preP = [touchpreviuslocationinview: self]; NSLog (@ "curP = % @", NSStringFromCGPoint (curP); NSLog (@ "preP = % @", NSStringFromCGPoint (preP )); CGFloat offsetX = curP. x-preP. x; CGFloat offsetY = curP. y-preP. y; // translate self. transform = CGAffineTransformTranslate (self. transform, offsetX, offsetY);} // call-(void) touchesEnded :( NSSet
   
    
*) Touches withEvent :( UIEvent *) event {NSLog (@ "% s" ,__ func __);} // This method will be called when a system event occurs (call in, automatic shutdown)-(void) touchesCancelled :( NSSet
    
     
*) Touches withEvent :( UIEvent *) event {NSLog (@ "% s" ,__ func _);} @ end
    
   
  
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.