I have an app that has the instagram-stories or snapchat stories feature . I display an image and on top of that image there is information like name and content . When I tap the image it is suppose to display another image but it doesn't only when using InsertSubview. Everything updates correctly except the image that I use as a subview . When i use AddSubview instead of InsertSubview then on tap it changes images however none of the content on top of the image would show then . What I think that is happening is that the new image is getting buried behind the old image since on every tap a new InsertSubview is created . Is there a way that I can fix this ? Again when using InsertSubview it gets stuck on the first image and does not change images on tap. I verified this by uploading a video it showed an image first and when I tapped the image I could here a video in the background eventhough it showed that first image .This is my code
On Touch
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self.view)
else if location.x < self.view.layer.frame.size.width / 2 {
if touchCount == 0 || touchCount < 0 {
touchCount = 0
} else {
touchCount = touchCount - 1
}
reloadTable(Offset: touchCount)
}
else {
touchCount = touchCount + 1
reloadTable(Offset: touchCount)
}
}
}
Uploads Image
func ShowImage(s_image: String) {
self.bookviewImage.imageView = nil
let imgURL: NSURL = NSURL(string: s_image)!
let request:NSURLRequest = NSURLRequest(url: imgURL as URL)
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
bookviewImage.imageView = UIImageView(image: UIImage(named: s_image))
bookviewImage.imageView?.frame = VideoView.bounds
bookviewImage.imageView?.contentMode = UIViewContentMode.scaleAspectFill
let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in
DispatchQueue.main.async(execute: { () -> Void in
if data != nil {
self.bookviewImage.imageView?.image = UIImage(data: data!)
self.VideoView.insertSubview(self.bookviewImage.imageView!, at: 0)
self.addChildViewController(self.bookviewImage)
// self.VideoView.addSubview(self.bookviewImage.imageView!)
} else {
// cell.Stream_Image_Height.constant = 0
self.bookviewImage.imageView!.image = nil
}
})
});
task.resume()
}
Http Request
func reloadTable(Offset: Int) {
// basic sends http request the offset is the touchCount
// I call the method below when the http data comes
// again this part works fine
ShowImage(s_image: s_image)
}