简体   繁体   English

iPhone:移动没有 Animation 的 UIButton

[英]iPhone: Move a UIButton without Animation

There are boatloads of hits on animating a UIButton move.动画 UIButton 动作有很多成功之处。 I want to do the opposite - move the button without animation.我想做相反的事情 - 移动没有 animation 的按钮。 Is it possible to move a button created in interface builder without animations?是否可以在没有动画的情况下移动在界面构建器中创建的按钮? If so, would someone mind sharing the method as there is no setPosition message.如果是这样,有人会介意分享该方法,因为没有setPosition消息。

Jeff杰夫

You will need an outlet for the button and you can use either frame , center or transform to move the button.您将需要一个按钮的插座,您可以使用framecentertransform来移动按钮。

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.这里的transform不会改变中心或框架,而只会移动按钮。

Yes, try to use setFrame: [button setFrame:CGRectMake(newX, newY, newWidth, newHeight)];是的,尝试使用 setFrame: [button setFrame:CGRectMake(newX, newY, newWidth, newHeight)];

How about setting different frame?设置不同的框架怎么样? you can move the button by setting different frame to it.您可以通过为其设置不同的框架来移动按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM