我有一个 UIImageView,我将它添加到 UIView 以增强识别触摸的区域。当我尝试将 UIImageView 在 UIView 中居中时(下面的代码),中心设置正确,但是当我运行程序时,图像显示在 UIView 框架之外。
有任何想法吗?
// image size is 32x32 pixels but view will be created with 44x44 so touch recognition is better
self = [super initWithFrame:CGRectMake(position.x, position.y, 44, 44)];
if (self) {
switch (color) {
case Blue:
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_red"]];
break;
case Green:
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_green"]];
default:
break;
}
[self setCenter:position];
[self addSubview:self.imageView];
[self setExclusiveTouch:YES];
[self setBackgroundColor:[UIColor clearColor]];
[self.imageView setCenter:position];
NSLog(@"uiview center: %@", NSStringFromCGPoint(self.center));
NSLog(@"image center: %@", NSStringFromCGPoint(self.imageView.center));
谢谢!