Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Demonstrates that the center point of a view remains the same during
- // use of CGAffineTransformScale
- #import "ViewController.h"
- @interface ViewController ()
- @property(readwrite) UIView* icon;
- @end
- @implementation ViewController
- @synthesize icon;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- CGRect bounds = CGRectMake(10, 10, 100, 100);
- UIView* v = [[UIView alloc] initWithFrame: bounds];
- [v setBackgroundColor:[UIColor yellowColor]];
- [self.view addSubview:v];
- icon = v;
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- NSLog(@"Previous center: %@", NSStringFromCGPoint(self.icon.center));
- [UIView animateWithDuration:1.2
- delay:1.0
- options:0
- animations:^{
- NSLog(@"Before center: %@", NSStringFromCGPoint(self.icon.center));
- CGAffineTransform transform = self.icon.transform;
- self.icon.transform = CGAffineTransformScale(transform, 0.5, 0.5);
- NSLog(@"After center: %@", NSStringFromCGPoint(self.icon.center));
- }
- completion:^(BOOL finished){
- // nothing
- NSLog(@"Completion center: %@", NSStringFromCGPoint(self.icon.center));
- }];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- } else {
- return YES;
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement