ユーザーのタッチを認識できるカスタム コントロール (UIButton など) を手動で作成しようとしています。
そのため、カスタム コントロールのスーパーレイヤーがスケーリングされている場合でも、ユーザーのタッチ ポイントがカスタム コントロールのフレームに含まれているかどうかを知りたいと考えています。
したがって、カスタム コントロールのスケーリングされたサイズを知る必要があります。
CALayer はこのプロパティまたは関数をサポートしていますか?
ごめん。以前のコードに問題があるため、次のようにコードを編集しました。
uiView1 = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)] autorelease];
uiView1.backgroundColor = [UIColor yellowColor];
uiView1.transform = CGAffineTransformScale(uiView1.transform, 2.0, 2.0);
scaledButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
scaledButton.frame = CGRectMake(100, 100, 100, 40);
[scaledButton setTitle:@"Test" forState:UIControlStateNormal];
nonscaledButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
nonscaledButton.frame = CGRectMake(100, 100, 100, 40);
[nonscaledButton setTitle:@"Test" forState:UIControlStateNormal];
[uiView1 addSubview:scaledButton];
[self.view addSubview:uiView1];
[self.view addSubview:nonscaledButton];
NSLog(@"uiButton1 width : %f, height : %f", scaledButton.frame.size.width, scaledButton.frame.size.height);
NSLog(@"uiButton1 width : %f, height : %f", scaledButton.layer.bounds.size.width, scaledButton.layer.bounds.size.height);
NSLog(@"uiButton1 width : %f, height : %f", scaledButton.realFrame(???).size.width, scaledButton.realFrame(???).size.height);
スケーリングされたサイズを取得する方法がわかりません... => scaledButton (200,80)
以下は実行結果です。
/Users/nice7285/Library/Caches/appCode10/DerivedData/RealSize-e4f66643/Build/Products/Debug-iphonesimulator/RealSize.app/RealSize Simulator セッションがプロセス 1567 で開始されました
2012-09-01 16:52:31.124 RealSize[1567:15d03] uiButton1 幅: 100.000000、高さ: 40.000000
2012-09-01 16:52:31.126 RealSize[1567:15d03] uiButton1 幅: 100.000000、高さ: 40.000000