您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页iOS中frame和transform的坑

iOS中frame和transform的坑

来源:伴沃教育

自定义了UIButton类,重写了该类的layoutSubviews方法,但是在layoutSubviews中计算子控件布局是使用的frame属性,然后在外部改变了transform属性后,然后就各种被虐,算出来的子控件frame没错,但就是显示不正常。找了一天的bug终于发现了下面的一段话

*** 如果在程序中改变了某个控件的transform,那么请不要使用frame计算子控件的布局,应该使用bounds+center代替 ***
官方文档上关于transform属性的说明:
Changes to this property can be animated. However, if the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务