0

Why did this author choose to use CALayers in this otherwise brilliant example (which I just worked through), rather than just doing everything in the UIView?

http://www.raywenderlich.com/36288/how-to-make-a-custom-control

Couldn't he have done this more simply by doing all rendering and touch control in the CALayer? Is there some performance or other advantage to spreading the functionality between three different classes?

Thanks. (Would ask in the comments after the example itself but its pretty old, don't think it'd get answered.)

NOTE: I had already read the suggested duplicate, and I don't think it answers the question. Note that I don't care about portability to a Mac... what advantage does the use of CALayers confer upon this specific example. I don't think I would lose anything if I collapsed everything into the UIView, and it would be simpler (perhaps he was just trying to demo CALayers -- its an otherwise brilliant example). Do the experts agree?

To expand on my edit, according to the related postings there is no advantage brought by CALayers to this example unless it will be ported to Mac. Is that not true?

Chris
  • 629
  • 1
  • 10
  • 28
  • You can't add touch controls to a `CALayer`. Since a `UIView` is really just a container, you can add things like `UIGestureRecognizer` to it. – JaredH Apr 20 '15 at 04:22
  • So... advantage UIView, correct? – Chris Apr 20 '15 at 04:31
  • It's not that there's an "advantage" to using the `UIView`. It entirely depends upon what you want to do. There's certain behaviors and tweaking that you cannot achieve directly on the `UIView` and instead must drop down to the `CALayer`. – JaredH Apr 20 '15 at 04:33
  • My hypothesis that I'm testing is that none of those advantages apply to that example. He is just doing basic rendering, which could have been done in the UIView, unless I misunderstand. I think you are referring to some advanced animations (if I read correctly). – Chris Apr 20 '15 at 04:51

0 Answers0