Move a View into Another view on button click in Swift iOS
<p>I am stumbled upon an issue in an application that i am making. I need to place one view into another view programmatically on button click.</p>

<p><a href="https://i.stack.imgur.com/tGudR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tGudR.png" alt="Initial State"></a></p>

<p>Now i need to move View 1 to the centre of View 2 on a button click with an animation. I tried to reposition the View1 to View 2 but i am not able to do it properly.</p>

<p><a href="https://i.stack.imgur.com/M5Ah0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M5Ah0.png" alt="Final Result"></a></p>

<p>This is the Final result that i am trying to achieve.</p>

<p>CODE FOR CREATING THE RED VIEW</p>

<pre><code>    My.cellSnapshot  = snapshopOfCell(cell)
            var center = cell.center
            My.cellSnapshot!.center = center
            My.cellSnapshot!.alpha = 0.0
            ingredientsTableView.addSubview(My.cellSnapshot!)


func snapshopOfCell(inputView: UIView) -&gt; UIView {
            UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0)
            inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
            let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage
            UIGraphicsEndImageContext()
            let cellSnapshot : UIView = UIImageView(image: image)
            cellSnapshot.layer.masksToBounds = false
            cellSnapshot.layer.cornerRadius = 0.0
            cellSnapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0)
            cellSnapshot.layer.shadowRadius = 5.0
            cellSnapshot.layer.shadowOpacity = 0.4
            return cellSnapshot
        }
</code></pre>

<p>Please help me in solving the problem.</p>

<p>Thanks in advance</p>