我正在尝试手动进行自定义控制(如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 模拟器会话以进程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
答案 0 :(得分:0)
你像CGAffineTransformScale一样获得CGRect:
CGAffineTransform newtransform = CGAffineTransformScale([scaledButton transform], 2.0, 2.0);
CGRect newFame = CGRectApplyAffineTransform(scaledButton.frame, newtransform);