开发者

iPhone: Move a UIButton without Animation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜