I have a superview which contains a ImageView
, a testView
, and some buttons. I created a UIView
which contains ImageView2
and a removebutton
.
When I add UIView
to UIImageView
, the contents of UIView
are not in the frame of UIView
. Because of that, I cannot apply pan gesture recognizer.
I have tried to apply constraints and to change the frame and centre of ImageView2
.
Below is the code I am using to create the above mentioned UIView
. How do I ensure that the contents of the UIView
are visible in the frame of the UIView
?
let rect = CGRect(x: self.imageView.center.x-30, y: self.imageView.center.y-30, width: 80, height: 80)
testview = UIView(frame: rect)
testview.layer.cornerRadius = testview.frame.width/2
testview.backgroundColor = UIColor.blackColor()
testview.clipsToBounds = true
imageView2 = UIImageView(frame: CGRect(x: testview.frame.minX+10, y: testview.frame.minY+10, width: 60, height: 60))
let rect2 = CGRect(x: self.testview.frame.maxX-17, y: self.testview.frame.minY, width: 20, height: 20)
removeButton = UIButton(frame: rect2)
removeButton.layer.cornerRadius = removeButton.frame.width/2
removeButton.backgroundColor = UIColor.blackColor()
removeButton.clipsToBounds = true
imageView2.layer.cornerRadius = imageView2.frame.width/2
imageView2.userInteractionEnabled = true
imageView2.clipsToBounds = true
testview.alpha = 0.3
imageView2.center = testview.center
imageView2.center = testview.center
testview.addSubview(imageView2)
testview.addSubview(removeButton)
testview.bringSubviewToFront(imageView2)
imageView.addSubview(testview)