Reputation: 103
Expected Behaviour
One Tap on a Table Cell will slide up a View (taking 250px tall) into view. Tapping on another row will update the View information corresponding to the row tapped. Tapping on the same row will slide down the View.
Errors Occurring
Context
The Info View is has constraints that place it's top at the bottom of the Superview / Screen.
Code Samples
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.localTableView.deselectRowAtIndexPath(indexPath, animated: true)
self.mapView.selectAnnotation(self.players[indexPath.row], animated: true)
self.populateInfoView(indexPath.row)
if(self.infoView.frame.origin.y == UIScreen.mainScreen().bounds.size.height){
self.showInfoView(true)
} else if (self.previouslySelectedRow == indexPath.row){
self.hideInfoView(true)
}
self.previouslySelectedRow = indexPath.row
}
func populateInfoView(index: Int){
self.infoCoverImage.image = UIImage(named: "\(self.players[index].profileImage)")
self.infoProfileImage.image = UIImage(named: "\(self.players[index].profileImage)")
self.infoPlayerName.text = self.players[index].name
self.infoTwitterName.text = self.players[index].twitterName
}
func showInfoView(animated: Bool){
let height = self.infoView.frame.size.height
let yPos = UIScreen.mainScreen().bounds.size.height - height
UIView.animateWithDuration(0.33, animations: {
self.infoView.frame.origin.y = yPos
}, completion: { finished in
println("Always called, even if the frame does not move")
})
self.infoVisible = true
}
func hideInfoView(animated: Bool){
let height = self.infoView.frame.size.height
let yPos = UIScreen.mainScreen().bounds.size.height
if(animated == true){
UIView.animateWithDuration(0.25, animations: {
self.infoView.frame.origin.y = yPos
})
} else {
self.infoView.frame.origin.y = yPos
}
self.infoVisible = false
}
Any help would be greatly appreciated. Thank you,
Upvotes: 0
Views: 307
Reputation: 103
[SOLVED] - The problem resulted because we used frame.origin's rather than constraints. If you want the view to persist, use constraints. If you have a repeatable sprite-like animation, use origin's.
Upvotes: 0