Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可点击区域圆形矩形ios_Ios_Objective C_Iphone_Swift - Fatal编程技术网

可点击区域圆形矩形ios

可点击区域圆形矩形ios,ios,objective-c,iphone,swift,Ios,Objective C,Iphone,Swift,我正在尝试在iOS中绘制“圆形/椭圆形/椭圆形”自定义UIView(使用swift) 我使用一个子类绘制UIView,如下所示 import Foundation import UIKit class CustomEllipse: UIView { override func drawRect(rect: CGRect) { var ovalPath = UIBezierPath(ovalInRect: rect) UIColor.grayColor().setFi

我正在尝试在iOS中绘制“圆形/椭圆形/椭圆形”自定义UIView(使用swift)

我使用一个子类绘制UIView,如下所示

import Foundation
import UIKit

class CustomEllipse: UIView {


  override func drawRect(rect: CGRect)
  {
    var ovalPath = UIBezierPath(ovalInRect: rect)
    UIColor.grayColor().setFill()
    ovalPath.fill()
  }

}
这将产生与以下类似的输出

我现在需要为这个“CustomEllipse”定义一个可点击的区域

但是,当我为“CustomElipse”定义UITapgestureRecognitor时,默认情况下,上面看到的黑色角落是可单击的


有没有办法只让灰色椭圆可点击?

您可以通过覆盖方法自定义可点击区域。 默认情况下,该区域与
边界
矩形相同

在这种情况下,可以使用
UIBezierPath
中的方法。像这样:

class CustomEllipse: UIView {

    var ovalPath:UIBezierPath?

    override func drawRect(rect: CGRect) {
        ovalPath = UIBezierPath(ovalInRect: rect)
        UIColor.grayColor().setFill()
        ovalPath!.fill()
    }

    override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
        return ovalPath?.containsPoint(point) == true
    }
}