Why cannot resizing UIView?
Skyline-23 opened this issue · comments
Buseong Kim commented
I am trying to resize with animation but it not works.
(only animation works)
and this is my code
import UIKit
import RxSwift
import RxGesture
import Then
import PinLayout
class ViewController: UIViewController {
private let view1: UIView = UIView().then {
$0.backgroundColor = .lightGray
}
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
[view1].forEach { self.view.addSubview($0) }
bind()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
self.view.endEditing(true)
}
// SafeArea, Rotate Code need to be written here
override func viewDidLayoutSubviews() {
self.view1.pin
.center()
.size(30)
}
private func bind() {
self.view1.rx.tapGesture()
.subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
UIView.animate(withDuration: 0.2) {
self.view1.pin
.size(100)
}
}).disposed(by: disposeBag)
}
}
Luc Dion commented
There could be a conflict between viewDidLayoutSubviews()
(which set the size to 30), and the animation block who set the size to 100. You should update a property containing the size and call self.view.setNeedsLayout()
from your animation block. But the exact reason why it doesn't work is strange. It would probably won't work either setting direction the frame
property? (self.view.frame = CGRect(0,0,100,100)
)