1

我正在尝试手动制作可以识别用户触摸的自定义控件(如 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

在此处输入图像描述

4

1 回答 1

0

像这样的 CGAffineTransformScale 之后,您会得到 CGRect:

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

 CGRect newFame = CGRectApplyAffineTransform(scaledButton.frame, newtransform);
于 2012-09-01T09:06:19.693 回答