mainView オブジェクトを作成しUIView
、それにサブビューを 1 つ追加しました。フレームサイズを縮小するために、mainView に変換を適用しました。ただし、mainView のサブビューの枠は縮小されませんでした。このサブビューのサイズを縮小する方法。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGFloat widthM=1200.0;
CGFloat heightM=1800.0;
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, widthM, heightM)];
mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"te.png"]];
[self.view addSubview:mainView];
CGFloat yourDesiredWidth = 250.0;
CGFloat yourDesiredHeight = yourDesiredWidth *heightM/widthM;
CGAffineTransform scalingTransform;
scalingTransform = CGAffineTransformMakeScale(yourDesiredWidth/mainView.frame.size.width, yourDesiredHeight/mainView.frame.size.height);
mainView.transform = scalingTransform;
mainView.center = self.view.center;
NSLog(@"mainView:%@",mainView);
UIView *subMainView= [[UIView alloc] initWithFrame:CGRectMake(100, 100, 1000, 1200)];
subMainView.backgroundColor = [UIColor redColor];
[mainView addSubview:subMainView];
NSLog(@"subMainView:%@",subMainView);
}
これらのビューの NSlog:
mainView:<UIView: 0x8878490; frame = (35 62.5; 250 375); transform = [0.208333, 0, 0, 0.208333, 0, 0]; layer = <CALayer: 0x8879140>>
subMainView:<UIView: 0x887b8c0; frame = (100 100; 1000 1200); layer = <CALayer: 0x887c160>>
ここで、mainView の幅は 250、サブビューの幅は 1000 です。しかし、シミュレーターで出力を取得すると、サブビューは正しく占有されていますが、mainView を超えていません。それはどのように可能ですか?変換後にmainViewフレームに関してサブビューのフレームを取得する方法は?