Alter CGRect (or any struct)?

后端 未结 3 2005

I do this quite a bit in my code:

self.sliderOne.frame  = CGRectMake(newX, 0, self.sliderOne.frame.size.width, self.sliderOne.frame.size.height); 

3条回答
  •  半阙折子戏
    2021-01-06 07:38

    The issue here is that self.sliderOne.frame.origin.x is the same thing as [[self sliderOne] frame].origin.x. As you can see, assigning back to the lValue here is not what you want to do.

    So no, that "tedious" code is necessary, although can be shortened up a bit.

    CGRect rect = thing.frame;
    thing.frame = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect) + 10, etc...);
    

提交回复
热议问题