myView.frame.origin.x = value; does not work - But why?

前端 未结 4 1668
北恋
北恋 2020-12-02 16:06

I know that I can\'t use this:

myView.frame.origin.x = 25.0;

and that I have to use this instead:

CGRect myFrame = myView.f         


        
4条回答
  •  被撕碎了的回忆
    2020-12-02 16:28

    A CGRect is a struct, which is something from standard C. A CGRect is not an Objective C object, so when you assign to one of its members, no setter method is called. Without a setter method being called, UIKit will not be able to know that anything has changed, and so will not be able to update the screen display.

    Edit: as has been pointed out, the assignment will be to a copy of the struct.

提交回复
热议问题