Linking two UIview frames / positions using Rxswift

I want to change the position of view2 automatically when the position of view1 changes and will bind both view positions using Rxswift.

I am trying to observe the frame / position of an image using this

view.rx.observe(CGRect.self,"frame")
        .subscribe(onNext: {
            print($0 ?? (0,0))
        })

      

it print the frame in init mode but when the view position is changed using constraints

self.constraintHorizontalCenterView.constant = 1000

      

it doesn't mean anything that this code doesn't respect the view position ...

Is there a way to watch for constant view position or view position anchors?

+3


source to share


2 answers


UIView.frame is not KVO compliant, so you cannot directly observe it. In any case, this is not in line with IMHO.



Some event causes your appearance to change. Observe this.

0


source


from apple < frame // animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.



Instead, you can see anchored or center.

0


source







All Articles