开发者

iPhone: Move a UIButton without Animation

开发者 https://www.devze.com 2023-03-20 03:49 出处:网络
There are boatloads of hits on animating a UIButton move. I want to do the opposite - move the button without animation. Is it possibl开发者_如何转开发e to move a button created in interface builder w

There are boatloads of hits on animating a UIButton move. I want to do the opposite - move the button without animation. Is it possibl开发者_如何转开发e to move a button created in interface builder without animations? If so, would someone mind sharing the method as there is no setPosition message.

Jeff


You will need an outlet for the button and you can use either frame, center or transform to move the button.

button.frame = newFrame; // where `newFrame` is the frame to move to.
button.center = newCenter; // where `newCenter` is a CGPoint 
button.transform = CGAffineTransformMakeTranslation( xDisplacement, yDisplacement);

Here transform doesn't change the center or the frame but only moves the button.


Yes, try to use setFrame: [button setFrame:CGRectMake(newX, newY, newWidth, newHeight)];


How about setting different frame? you can move the button by setting different frame to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号