Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

ios - How is the relation between UIView's clipsToBounds and CALayer's masksToBounds?

A UIView has a CALayer. That's pretty sure. But both seem to provide something that means the same thing.

If I'd set clipsToBounds=YES, would this also set the layer's masksToBounds=YES? Why different names? Anyone knows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

They are different names because UIView and CALayer are different and have different terminology associated with them, but they are functionally equivalent. If you disassemble clipsToBounds you will see it just calls masksToBounds (disassembly from the simulator framework, so x86):

-(BOOL)[UIView(Rendering) clipsToBounds]
    +0  3091938a  55              pushl    %ebp
    +1  3091938b  89e5            movl     %esp,%ebp
    +3  3091938d  e800000000      calll    0x30919392
    +8  30919392  59              popl     %ecx
    +9  30919393  8b4508          movl     0x08(%ebp),%eax
   +12  30919396  8b5004          movl     0x04(%eax),%edx         (CALayer)_layer
   +15  30919399  8b8186cb1301    movl     0x0113cb86(%ecx),%eax    masksToBounds
   +21  3091939f  89450c          movl     %eax,0x0c(%ebp)
   +24  309193a2  895508          movl     %edx,0x08(%ebp)
   +27  309193a5  c9              leave
   +28  309193a6  e92e211801      jmpl     0x31a9b4d9

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...