使用动画从按钮位置放大和缩小UIView

时间:2018-11-30 09:52:18

标签: ios iphone swift animation

我想在按钮单击时打开UIView,并且应该从按钮的初始位置弹出视图,同时在图库中打开与图像相同的屏幕。点击图片时,图片会从点击位置打开,并覆盖整个屏幕。我希望按钮单击时与UIView相同。我试过下面的代码:

初始位置:

UIView.animate(withDuration: 0.9, delay: 0.0, options: .curveLinear, animations: {
    self.vwDetails.frame = CGRect(x: self.btnSelectedVendor.frame.origin.x, y: self.btnSelectedVendor.frame.origin.y, width: self.btnSelectedVendor.frame.width, height: self.btnSelectedVendor.frame.height)
}, completion: nil)

在按钮上单击:

UIView.animate(withDuration: 0.9, delay: 0.0, options: .curveLinear, animations: {
    self.vwDetails.frame = CGRect(x: self.vwContainer.frame.origin.x, y: self.vwContainer.frame.origin.y, width: self.vwContainer.frame.width, height: self.vwContainer.frame.height)
}, completion: nil)

此代码不适用于我。

谢谢。

3 个答案:

答案 0 :(得分:0)

我认为您需要这样的东西:

self.vwDetails.frame = CGRect(x: self.vwContainer.frame.origin.x, y: self.vwContainer.frame.origin.y, width: self.vwContainer.frame.width, height: self.vwContainer.frame.height)

首先设置初始位置

UIView.animate(withDuration: 0.9, delay: 0.0, options: .curveLinear, animations: {
    self.vwDetails.frame = CGRect(x: self.vwContainer.frame.origin.x, y: self.vwContainer.frame.origin.y, width: self.vwContainer.frame.width, height: self.vwContainer.frame.height)
}, completion: nil)

开始动画后

答案 1 :(得分:0)

要同时实现翻译和扩展,您需要以下内容:

let originalTransform = yourView.transform
let scaledTransform = originalTransform.scaledBy(x: 0.2, y: 0.2)
let scaledAndTranslatedTransform = scaledTransform.translatedBy(x: 0.0, y: -250.0)
UIView.animate(withDuration: 0.7, animations: {
  self.main.transform = scaledAndTranslatedTransform
})

答案 2 :(得分:0)

尝试一下

替换您的代码

pipe.predict()

与此:

UIView.animate(withDuration: 0.9, delay: 0.0, options: .curveLinear, animations: {
    self.vwDetails.frame = CGRect(x: self.vwContainer.frame.origin.x, y: self.vwContainer.frame.origin.y, width: self.vwContainer.frame.width, height: self.vwContainer.frame.height)
}, completion: nil)

您可以根据自己的需求调整位置

相关问题