0

I have such hierarchy:

  • scroll view
  • --- container view
  • ----- cycle view

enter image description here

This scroll view also can zoom. And I need to show view2 in center of cycle view when I pressed this cycle view(there I have tap gesture recogniser). But view2 should be lye on container view because we also need to zoom it with cycle view.

I try to get rect where need to show view2 with this approach.

func getSourceRect(for cycleView: UIView) -> CGRect {
   let rectOnContainer = cycleView.convert(cycleView.frame, to: containerView)
   let rectOnScrollView = containerView.convert(rectOnContainer, to: scrollView)
        
   return rectOnScrollView
}

and then I do next

let sourceRect = getSourceRect(for: cycleView)
view2.center = CGPoint(x: sourceRect.midX, y: sourceRect.midY)

It doesn't work. Please help me understood this behaviour and get this position where I can show view2

3
  • So you want view2 to be centered on the cycle view but attached to the container view? Commented Nov 29, 2021 at 20:20
  • Is cycleview's parent container view? Commented Nov 29, 2021 at 20:21
  • 1
    @Biclops yes, need to be centered. And also cycleview's parent is container view. Commented Nov 29, 2021 at 20:23

1 Answer 1

1

So you want view2 to be centered on the cycle view but attached to the container view?

If this is true then

// if view2 and cycle view's parent is container view 
// then there should not be a need to transform view2's 
// coordinate space
view2.center = cycleView.center

// make sure z position is correct so that cycle view isn't obscuring
// view2's visibility.
view2.parent?.bringSubviewToFront(view2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.