layoutBox / PinLayout

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why cannot resizing UIView?

Skyline-23 opened this issue · comments

I am trying to resize with animation but it not works.
(only animation works)

this is my screen recording
Simulator Screen Recording - iPhone 13 Pro - 2021-12-29 at 19 44 04

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)
    }

}

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))