2012-09-01 52 views
1

我正在嘗試自定義控件(如UIButton)來手動識別用戶的觸摸。是否有可能獲得縮放大小的UIControl?

因此,甚至當自定義控件的超級縮放比例爲,我想知道用戶的觸摸點是否包含在自定義控件的框架中。

因此我需要知道自定義控件的縮放大小。

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 模擬器會話開始處理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

enter image description here

回答

0

你得到的CGRect後像CGAffineTransformScale這樣的:

CGAffineTransform newtransform = CGAffineTransformScale([scaledButton transform], 2.0, 2.0); 

CGRect newFame = CGRectApplyAffineTransform(scaledButton.frame, newtransform); 
+0

檢查我的答案 –

+0

我認爲這個答案是暗示。 –

相關問題