Advertisement
Guest User

UIView center with CGAffineTransformScale

a guest
Sep 24th, 2012
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Demonstrates that the center point of a view remains the same during
  2. // use of CGAffineTransformScale
  3. #import "ViewController.h"
  4.  
  5. @interface ViewController ()
  6. @property(readwrite) UIView* icon;
  7. @end
  8.  
  9. @implementation ViewController
  10.  
  11. @synthesize icon;
  12.  
  13. - (void)viewDidLoad
  14. {
  15.     [super viewDidLoad];
  16.  
  17.     CGRect bounds = CGRectMake(10, 10, 100, 100);
  18.     UIView* v = [[UIView alloc] initWithFrame: bounds];
  19.     [v setBackgroundColor:[UIColor yellowColor]];
  20.     [self.view addSubview:v];
  21.    
  22.     icon = v;
  23. }
  24.  
  25. - (void)viewDidUnload
  26. {
  27.     [super viewDidUnload];
  28.     // Release any retained subviews of the main view.
  29. }
  30.  
  31. - (void)viewDidAppear:(BOOL)animated
  32. {
  33.     NSLog(@"Previous center: %@", NSStringFromCGPoint(self.icon.center));
  34.    
  35.     [UIView animateWithDuration:1.2
  36.               delay:1.0
  37.             options:0
  38.          animations:^{
  39.              NSLog(@"Before center: %@", NSStringFromCGPoint(self.icon.center));
  40.              
  41.              CGAffineTransform transform = self.icon.transform;
  42.              self.icon.transform = CGAffineTransformScale(transform, 0.5, 0.5);
  43.              
  44.              NSLog(@"After center: %@", NSStringFromCGPoint(self.icon.center));
  45.          }
  46.          completion:^(BOOL finished){
  47.              // nothing
  48.              NSLog(@"Completion center: %@", NSStringFromCGPoint(self.icon.center));
  49.          }];
  50.    
  51. }
  52.  
  53. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  54. {
  55.     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  56.         return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  57.     } else {
  58.         return YES;
  59.     }
  60. }
  61.  
  62. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement