English 中文(简体)
如果已经增加一名医疗顾问作为子站
原标题:Check if a CALayer is already added as a sublayer

我每人有5个疗养院,是财产。 Saye 我将其中3个列为次调查。 如果某一层已经添加到该层,我需要ba。

最佳回答

您是否尝试了<条码>代号财产? 如果在任何地方增加你的一层。

问题回答
if (layer.superlayer == parentLayer) {
    ...
} else {
    ...
}

意见.layer.sublayers 给你一系列次层,看看你是否添加了你的一层,可以做些什么,如观点、继器、计数以及一层计达到你预期的外观。

if (view.layer.sublayers.count  < 3) {
//add layer
}else{
// do nothing because the layer has already been added.
}

你们还可以审查子站各层,以更好地确定你所期待的层次。 由于它们是特性,你应当能够与阵列中的每一层进行比较,以了解你所期望的层次是否得到增加。

我需要检查一下,看看一位梯度律师是否是另一个观点的副手。 这是那里唯一的一层,因此我不得不检查任何其他东西。 以上答复对我来说是徒劳的。

I came across this answer and even though it was used for a different reason it was an easy way to check if the gradientLayer was a child of another view s layer property (the parentLayer) and it works fine for me:

if let _ = (yourParentView.layer.sublayers?.compactMap { $0 as? CAGradientLayer })?.first {

    print("the gradientLayer IS already a subLayer of this parentView s layer property")
} else {

    print("the gradientLayer IS NOT a subLayer of this parentView s layer property")
}

页: 1

if view.layer.sublayers == nil {

    // add Sublayer

}
  • /检查CALayer Contains Sublayer(shpapelayer/textlayer)

                               if myShapeLayer.sublayers?.count>0
                               {
                                   var arr:NSArray? = myShapeLayer.sublayers as NSArray
                                   var i:Int=0
                                   for i in 0..<arr!.count
                                   {
                                       var a: AnyObject = arr!.objectAtIndex(i)
                                       if a.isKindOfClass(CAShapeLayer) || a.isKindOfClass(CATextLayer)
                                       {
                                           if a.isKindOfClass(CAShapeLayer)
                                           {
                                               a = a as! CAShapeLayer
    
                                               if CGPathContainsPoint(a.path, nil, pointOfCircle, true)
                                               {
                                                   NSLog("contains shape layer")
    
                                               }
                                               else
                                               {
                                                   NSLog("not  contains shape layer")
    
                                               }
                                           }
                                           if a.isKindOfClass(CATextLayer)
                                           {
                                               a = a as! CATextLayer
                                               var fr:CGRect = a.frame as CGRect
                                               if CGRectContainsPoint(fr, pointOfCircle)
                                               {
                                                   NSLog("contains textlayer")
    
                                               }
                                               else
                                               {
                                                   NSLog("not contains textlayer")
    
                                               }
                                           }
    
                                       }
                                   }
                               }
    




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签