Sco*_*ttS 5 iphone graphics interface-builder
我正试图在iPhone视图上放置一个圆形图像,然后在圆圈内部使用水龙头但不在其外部.我遇到的问题是,当我在界面生成器的屏幕视图上放置UIImageView时,我似乎被限制为矩形.我尝试使用圆形图像,圆圈外面的区域保持透明但图像总体上仍然是矩形的,所以当它放在UIImageView上并连接到识别水龙头手势时,它仍然会拾取圆圈外部的水龙头.
下图显示了我的意思.蓝点表示保存图像的UIImageView的外边框.点击手势识别当前链接到该UIImageView,但正如您所看到的,UIImageView的角落处有一些空间未被圆形图像覆盖.是否有任何方法既可以将UIImageView符合非矩形形状,也可以在不使用UIImageView的情况下将图像放置在视图上,并且仍然能够连接点击识别?
在UIImageView上透明背景的沃尔特的形象http://img237.imageshack.us/img237/2164/walterheadshot.png
我对iPhone图形很陌生,但是有没有人对此有所了解或能指出我正确的方向?
谢谢!
假设是一个圆形,而不仅仅是一个椭圆形:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGFloat halfSize = [self bounds].size.width * 0.5f;
CGPoint location = [[touches anyObject] locationInView:self];
location.x -= halfSize;
location.y -= halfSize;
CGFloat squaredDistanceFromCenter = location.x * location.x + location.y + location.y;
if (squaredDistanceFromCenter < (halfSize * halfSize)) {
NSLog(@"Within circle :)");
} else {
NSLog(@"Not within circle :(");
}
}
Run Code Online (Sandbox Code Playgroud)