0

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

4

1 回答 1

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

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

于 2011-06-29T07:09:37.863 回答