ビューに(たとえば、スケール= 3.0)を適用した後 CGAffineTransformMakeScale(scale,scale)
、スケーリングは問題ありません。しかし、スケーリング後にサブビューをプログラムで挿入しようとすると、サブビューも3倍にスケーリングされ、スケーリングしたくありません。私が間違っていることは何ですか?
1591 次
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];
> }
//解決策:サブビューもスーパービューと同じように拡大縮小されるため、考えられる解決策は、サブビューを元のサイズに再拡大縮小することです。たとえば、スーパービューを2.0,2.0にスケーリングした場合、必要に応じて元のフレームでサブビューを追加してから、CGAffineTransformMakeScale(0.5,0.5);を適用すると、問題が解決すると思います。enter code here
//また、変換を適用すると、原点も変更されます。変換後に(0,0)にリセットできます。
于 2011-06-29T07:09:37.863 に答える