CGAffineTransformMakeScale and inserting subviews
After i apply CGAffineTransformMakeScale(scale,scale)
(for example scale = 3.0) to the view - it's scaling ok. But when I'm trying to programmatically insert some subview after scaling - subview also scales 开发者_运维知识库by 3 times - and I don't want it to be scaled. What I'm doing wrong?
- (void)viewDidLoad {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
// other animations goes here
//imageView is a global variable of UIImageView with frame
//CGrectMake(0,0,160,240);
imageView.transform =CGAffineTransformMakeScale(2.0,2.0);//CGAffineTransformMakeRotation(M_PI*0.5);
// other animations goes here
[UIView commitAnimations];
[super viewDidLoad];
NSLog(@"THe imageView rect is %@",NSStringFromCGRect(imageView.frame));
[self performSelector:@selector(addImage) withObject:nil afterDelay:1.5];
}
//adding subview as you needed.
> -(void)addImage {
>
>
> CGRect rect=imageView.frame;
> rect.origin.x=0;
> rect.origin.y=0;
> [imageView setFrame:rect];
> UIImageView *imageViewTwo=[[UIImageView alloc] initWithImage:
> [UIImage=imageNamed:@"photo-4.PNG"]];
> [imageViewTwo setFrame:CGRectMake(0, 0, 160,
> 240)];//it will be scaled two //times
> as its superview
> [imageView addSubview:imageViewTwo];
> NSLog(@"the frame of the subv iew is
> %@",NSStringFromCGRect(imageViewTwo.frame));
> [imageViewTwo release];
> }
//Resolution : Subview will also be scaled , as much as the superview, so , the possible solution will be to rescale the subView to its original size. For example
if you have scaled superview to 2.0,2.0 , add sub view with original frame as you needed, then apply CGAffineTransformMakeScale(0.5,0.5);, I think it will solve your problem. enter code here
//Also, after we apply transform, the origin also changes. We can reset it to (0,0) after transform.
精彩评论