이 효과를 얻으려고 노력하고 있습니다.
https://cdn.dribbble.com/users/124059/screenshots/3727352/400.gif
이것을 위해 내가하고있다 :
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardTableViewCell
UIView.animate(withDuration: 0.5, delay: 0.3, usingSpringWithDamping: 0.1, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
cell.coverImageView.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
}, completion: nil)
}
그러나이 코드는 UIImageView 내부의 이미지가 아닌 UIImageView 프레임의 크기를 조정합니다.
코드를 어떻게 개선 할 수 있습니까?
트릭은 imageView의 프레임을 엉망으로 만들고 콘텐츠 모드가 변경되는 것처럼 보이게 만드는 것입니다. 프레임이나 제약 조건을 조작하여 다른 뷰 내에서 마스킹 할 수 있습니다. 예제를 실행하고 알려주세요.
import UIKit
class ViewController: UIViewController {
var imageView = UIImageView()
var maskView = UIView()
var frame : CGRect = .zero
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.layoutIfNeeded()
imageView = UIImageView(frame: CGRect(x: 20, y: 40, width: view.bounds.width-40, height: view.bounds.height/2))
imageView.image = UIImage(named: "img")
imageView.contentMode = .scaleAspectFill
maskView = UIView(frame: CGRect(x: 20, y: 40, width: view.bounds.width-40, height: view.bounds.height/2))
maskView.addSubview(imageView)
maskView.layer.masksToBounds = true
maskView.layer.cornerRadius = 6
self.view.addSubview(maskView)
//manipulate the imageView to make the content mode seem to change
// and have it redraw itself
frame = imageView.frame
var newFrame = frame
newFrame.size.height += newFrame.height
imageView.frame = newFrame
imageView.center = maskView.center
let button = UIButton(frame: CGRect(x: 20, y: maskView.frame.maxY + 60, width: view.bounds.width - 40, height: 40))
button.setTitle("Animate", for: .normal)
button.setTitleColor(.blue, for: .normal)
button.addTarget(self, action: #selector(ViewController.pressed), for: .touchUpInside)
self.view.addSubview(button)
let AnotherButton = UIButton(frame: CGRect(x: 20, y: button.frame.maxY + 20, width: view.bounds.width - 40, height: 40))
AnotherButton.setTitle("Reset", for: .normal)
AnotherButton.setTitleColor(.blue, for: .normal)
AnotherButton.addTarget(self, action: #selector(ViewController.reset), for: .touchUpInside)
self.view.addSubview(AnotherButton)
}
func pressed() {
//animate
// screw around with the imageView back to the original frame
// you could also do this with the height constraints if it was constraint based
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1.0, options: .curveEaseOut, animations: {
self.imageView.frame = self.maskView.bounds
}, completion: nil)
}
func reset() {
//reset big frame
var newFrame = frame
newFrame.size.height += newFrame.height
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseOut, animations: {
self.imageView.frame = newFrame
self.imageView.center = self.maskView.center
}, completion: nil)
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다