CGAffineTransformMakeScale并插入子视图

时间:2011-06-29 06:31:21

标签: iphone cocoa ipad uiview cgaffinetransform

在我将CGAffineTransformMakeScale(scale,scale)(例如scale = 3.0)应用于视图后 - 它可以缩放。但是当我尝试以编程方式在缩放后插入一些子视图时 - 子视图也会缩放3次 - 我不希望它被缩放。我做错了什么?

1 个答案:

答案 0 :(得分:0)

    - (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];


}

//根据需要添加子视图。

> -(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];
>        }

//分辨率:子视图也将被缩放,与superview一样多,因此,可能的解决方案是将subView重新缩放到其原始大小。例如 如果您将superview缩放到2.0,2.0,请根据需要添加带原始帧的子视图,然后应用CGAffineTransformMakeScale(0.5,0.5);我认为它将解决您的问题。 enter code here //此外,在我们应用变换后,原点也会发生变化。我们可以在变换后将其重置为(0,0)。