是否可以创建如下图所示的两个按钮?它可能看起来像你应该使用UIButton或UIImageView,但如果我点击区域1,它仍然作为点击按钮1.按钮2应该被解雇,当我点击区域1以及!iOS上的圆形按钮
回答
是的,当然是可以的。
您可以通过IB有多个选择连接一个动作。
您也可以直接从button1触发的方法内部调用button2触发的方法。
这相当棘手,但有可能: 只能使用一个按钮,但把一些验证事件touchUpInside后。你应该计算这个接触点是否在“button1”的圆圈内。对于这个任务,你需要有一些数学知识 - How do I calculate a point on a circle’s circumference?
你可以通过你的切割按钮的层,并设置半径作圆形状的按钮。
[[按钮层] setCornerRadius:8.0f];
你也可以尝试改变半径。
设置cornerRadius只影响图像,area1仍然可以点击顶部按钮 – Bot 2014-07-14 21:14:50
设置userInteractionEnabled为NO小按钮1.所有事件将进入更大的按钮2.
我已经创建了两个圆矩形按钮用于此目的,其中之一是长而薄,另一个更宽。他们一起构建了一个胖乎乎的加号形状,这个形状非常接近圆形,考虑到苹果可以接受44像素作为最小可压缩尺寸。如果要更改图像,请将另一图像设置为其imageView以显示突出显示的状态,并将两个按钮的多个操作(如果想要在图像视图中模仿按钮高亮显示的状态,则不会足够)。或者,您可以添加观察者并根据按钮更改imageview的突出显示状态
如果未能将上述响应接受,您可以实施替代pointInside:withEvent:
的UIButton
自定义子类。
假设你的视图正好是正方形和图形精确的圆形和填充整个方形,其示例可以是:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// check that the point is at least inside the normal rect
if(![super pointInside:point withEvent:event]) return NO;
// we'll assume a square view with an exact circle inside, so
// the radius of the circle is just half the width
CGFloat radius = self.bounds.size.width*0.5f;
// the point (radius, radius) is also the centre of the view, so...
CGFloat squareOfDistanceFromCentre =
(radius - point.x)*(radius - point.x) +
(radius - point.y)*(radius - point.y);
// if the point is too far away, return NO
if(squareOfDistanceFromCentre > radius*radius) return NO;
// otherwise we've exhausted possible reasons for answering NO
return YES;
}
干净的方式来处理pointInside上的圆形按钮是这样的:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (![super pointInside:point withEvent:event])
{
return NO;
}
BOOL isInside = (pow((point.x-self.frame.size.width/2), 2) + pow((point.y - self.frame.size.height/2), 2) < pow((self.frame.size.width/2), 2)) ? YES:NO;
return isInside;
}
您可以沟“isInside” variabe,但这种方式更容易进行测试。
- 1. 圆形按钮
- 2. 圆形按钮
- 3. 圆形按钮
- 4. iOS:带四个圆形按钮的动画圆形
- 5. UIImage按钮(圆形按钮)
- 6. 绘制一个半圆形按钮iOS
- 7. 在Android中实现iOS圆形按钮
- 8. 圆形按钮形成
- 9. 在圆形按钮上居中文本
- 10. 悬停时有方圆按钮的圆形按钮
- 11. 的Android环形状为圆形按钮
- 12. NSToolbar中的圆形矩形按钮
- 13. 自定义圆形按钮
- 14. 圆形按钮组视图
- 15. 实施圆形按钮
- 16. GTK和CSS:圆形按钮
- 17. 创建圆形按钮
- 18. 移相器,圆形按钮
- 19. 圆形按钮与图像
- 20. 圆形按钮tkinter python
- 21. (jquery)圆形按钮组?
- 22. iOS PopOver - 仅限酒吧按钮项目或圆形矩形?
- 23. Xcode 5圆形矩形按钮
- 24. 圆形矩形按钮连接到ViewController.h
- 25. 圆形到圆形三角形(菜单按钮切换)
- 26. 如何制作圆形的椭圆形按钮?
- 27. 无法为我的圆形按钮添加阴影 - Swift iOS Dev
- 28. IOS /故事板/ Autolayout:单杠下的中央圆形按钮
- 29. 如何制作类似iOS 7锁屏的圆形按钮
- 30. 的Android定制的圆形按钮
除非你需要两个动作,为什么不把他们作为一个单一的图像装入一个看不见的按钮? – 2012-03-26 12:11:10