2

I need to create a UI which is a mix of UITableView, UITextField, and some custom UIView's and I also need to provide a custom focus animation.

How can I get the UITableView/UITableViewCell and UITextField to not render the default focus animations?

I tried:

    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        if let view = context.previouslyFocusedView {
            view.layer.removeAllAnimations()
        }
        if let view = context.nextFocusedView {
            view.layer.removeAllAnimations()
        }
    }

I can add my own animations, but can't get rid of the 'default' animations from the view.

pstoppani
  • 2,531
  • 1
  • 20
  • 20

3 Answers3

2

Change the focus style of the cell to custom instead of default.

cell.focusStyle = UITableViewCellFocusStyle.custom
SINDHYA PETER
  • 965
  • 9
  • 35
1

To remove focus from UITableViewCells, use this code:

 func tableView(_ tableView: UITableView, canFocusRowAt indexPath: IndexPath) -> Bool {
    return false
}
anas.p
  • 2,246
  • 19
  • 26
  • 4
    This is incorrect. The question is asking how can one disable the default focus animation not prevent focusing on an item. – Reza Shirazian Apr 15 '17 at 06:24
0

I've solved my problem with which is similar to your question but my UITableView which has just one UITableViewCell. So when UIViewController present / load there is no focused UITableViewCell and when I click cell it perform its action ( present an UIAlertController)

    if let focusedCell = UIScreen.main.focusedView as? MyCell{

         focusedCell.backgroundColor = UIColor.clear
    }

then

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    // take action
    ... alertController configuration
    present(alertController, animated: true, completion: {

          tableView.reloadData()

    })

}

When table has reloaded itself it convert its not focused form and the cycle is repeat itself.

eemrah
  • 1,603
  • 3
  • 19
  • 37