Quite often, I’ll want to move an object along by 2 points, so I’ll put:
CGRectMake(currentobject.frame.origin.x+2, currentObject.frame.origin.y, currentObject.frame.size.width, currentObject.frame.size.height);
Is there a quicker way, where either I can just change the 1 thing, or where I can quickly reference the current values?
You should use
CGRectOffset():Note the assertion: a method with a struct return value is one of the few cases where sending a message to
nilcan return junk rather than some equivalent to zero (0, 0.0,nil,Nil, &c.).The equivalent of
CGRectOffset()for growing or shrinking the frame (changing the size) isCGRectInset().An alternative to using
CGRectOffset()when working withUIViewis to just displace the view’s center:This updates the frame accordingly.