frame.origin Change error on View when Table Cell selected

severus Source

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

  1. The first tap is recognized (and math changes for the frame.origin), but the View does not move. A second tap on the same cell is required to for the View to slide up (the same math occurs for the frame.origin).
  2. Tapping another another row moves the View back to the bottom of the screen, even though the action is not called to hide the Info view.

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,



answered 2 years ago severus #1

[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.

comments powered by Disqus