1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad { [super viewDidLoad];
[self lastTransform]; } # -(void)lastTransform{ UIView *changeView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; changeView.tag = 20; changeView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:changeView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(50, 50, 50, 50); button.backgroundColor = [UIColor blueColor]; [button addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)onClick{
UIView *changeView = [self.view viewWithTag:20];
changeView.transform = CGAffineTransformTranslate(changeView.transform, 10, 0);
CGFloat angle = [self getAgreeFromDegree:10]; changeView.transform = CGAffineTransformRotate(changeView.transform, angle);
NSLog(@"%@",NSStringFromCGRect(changeView.frame)); NSLog(@"%f",changeView.bounds.size.width); NSLog(@"%f",changeView.bounds.size.height); NSLog(@"%f",changeView.center.x); NSLog(@"%f",changeView.center.y); } #pragma mark - #pragma mark 形变
-(void)transform{ UIView *changeView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)]; [view1 setBackgroundColor:[UIColor blueColor]]; [changeView addSubview:view1]; changeView.backgroundColor = [UIColor yellowColor];
changeView.transform = CGAffineTransformMakeTranslation(0, 100);
CGFloat angle = [self getAgreeFromDegree:20]; changeView.transform = CGAffineTransformMakeRotation(angle); [self.view addSubview:changeView]; } -(CGFloat)getAgreeFromDegree:(CGFloat)degree{ CGFloat agree = degree * M_PI / 180; return agree; }
-(void)createUIView{
UIView *orangeView = [[UIView alloc]init];
orangeView.backgroundColor = [UIColor orangeColor];
orangeView.frame = CGRectMake(0, 0, 100, 100);
orangeView.center = CGPointMake(0, 0); orangeView.center = self.view.center;
[self.view addSubview:orangeView]; }
@end
|