2015-11-16 5 views
3

Я пытаюсь оживить UITableView, чтобы действовать как dropdownMenu, используя его ограничение по высоте и блок UIView.animateWithDamping (..). У меня возникает странная проблема с белым фоном в tableView.

iPhone Simulator showing the problemUITableView демпфирующая анимация и ограничения макета

Я освобождал каждый цвет фона, и это не помогает.
Вот установка всех подвидов из dropDownView, который является UIView код:

required public init?(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 
    self.elements = [] 
    defaultSetup() 
} 

private func defaultSetup() { 
    configureActionButton() 
    configureTableView() 
} 
private func configureActionButton() { 
    actionButton = UIButton(frame: CGRectZero) 
    actionButton.translatesAutoresizingMaskIntoConstraints = false 
    addSubview(actionButton) 
    guard let superview         = actionButton.superview else { 
     assert(false, "ActionButton adding to superview failed.") 
     return 
    } 
    // Constraints 
    actionButton.constrain(.Leading, .Equal, superview, .Leading, constant: 0, multiplier: 1)?.constrain(.Trailing, .Equal, superview, .Trailing, constant: 0, multiplier: 1)?.constrain(.Top, .Equal, superview, .Top, constant: 0, multiplier: 1)?.constrain(.Bottom, .Equal, superview, .Bottom, constant: 0, multiplier: 1) 
    // Appearance 
    actionButton.backgroundColor      = UIColor.clearColor() 
    actionButton.opaque         = false 
    actionButton.contentHorizontalAlignment    = .Left 
    actionButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0) 
    if borderVisible { 
     actionButton.layer.cornerRadius     = 5 
     actionButton.layer.borderColor     = UIColor.blackColor().CGColor 
     actionButton.layer.borderWidth     = 1 
     actionButton.clipsToBounds      = true 
    } 
    // Actions 
    actionButton.addTarget(self, action: "menuAction:", forControlEvents: .TouchUpInside) 
} 

private func configureTableView() { 
    tableView           = BOTableView(frame: CGRectZero, items: elements, configuration: configuration) 
    tableView.translatesAutoresizingMaskIntoConstraints = false 
    tableView.delegate         = self 
    tableView.dataSource        = self 
    addSubview(tableView) 
    guard let tableViewSuperview = tableView.superview else { 
     assert(false, "TableView adding to superview failed.") 
     return 
    } 
    // Constraints 
    tableView.constrain(.Trailing, .Equal, tableViewSuperview, .Trailing, constant: 0, multiplier: 1)?.constrain(.Top, .Equal, tableViewSuperview, .Bottom, constant: 0, multiplier: 1)?.constrain(.Leading, .Equal, tableViewSuperview, .Leading, constant: 0, multiplier: 1) 
    tvHeightConstraint         = NSLayoutConstraint(item: tableView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 0) 
    tableView.addConstraint(tvHeightConstraint) 

} 

BOTableView класс инициализатор:

init(frame: CGRect, items: [String], configuration: BOConfiguration) { 
    super.init(frame: frame, style: UITableViewStyle.Plain) 

    self.items        = items 
    self.selectedIndexPath     = NSIndexPath(forRow: 0, inSection: 0) 
    self.configuration      = configuration 

    // Setup table view 
    self.opaque        = false 
    self.backgroundView?.backgroundColor = UIColor.clearColor() 
    self.backgroundColor     = UIColor.clearColor() 
    self.separatorColor      = UIColor.blackColor() 
    self.scrollEnabled      = false 
    self.separatorStyle      = .SingleLine 

    self.layer.cornerRadius     = 5 
    self.layer.borderColor     = UIColor.blackColor().CGColor 
    self.layer.borderWidth     = 1 
    self.clipsToBounds      = true 
} 

UIView анимации:

private func showMenuWithCompletionBlock(completion: (succeeded: Bool) -> Void) { 
    delegate?.menuWillShow(self) 
    let tvHeight       = frame.size.height * CGFloat(elements.count) 
    tvHeightConstraint.constant    = tvHeight 

    UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.5, options: .CurveEaseInOut, animations: { [weak self]() -> Void in 
      guard let strongSelf = self else { 
       completion(succeeded: false) 
       return 
      } 
      strongSelf.layoutIfNeeded() 
      }, completion: { (finished) -> Void in 
       if finished { 
        completion(succeeded: true) 
       } 
     }) 
} 

Вот код расширения UIView + Constraints, используемый в коде:

extension UIView { 
/** 
:returns: true if v is in this view's super view chain 
*/ 
public func isSuper(v : UIView) -> Bool 
{ 
    for var s : UIView? = self; s != nil; s = s?.superview { 
     if(v == s) { 
      return true; 
     } 
    } 
    return false 
} 

public func constrain(attribute: NSLayoutAttribute, _ relation: NSLayoutRelation, _ otherView: UIView, _ otherAttribute: NSLayoutAttribute, constant: CGFloat = 0.0, multiplier : CGFloat = 1.0) -> UIView? 
{ 
    let c = NSLayoutConstraint(item: self, attribute: attribute, relatedBy: relation, toItem: otherView, attribute: otherAttribute, multiplier: multiplier, constant: constant) 

    if isSuper(otherView) { 
     otherView.addConstraint(c) 
     return self 
    } 
    else if(otherView.isSuper(self) || otherView == self) 
    { 
     self.addConstraint(c) 
     return self 
    } 
    assert(false) 
    return nil 
} 

public func constrain(attribute: NSLayoutAttribute, _ relation: NSLayoutRelation, constant: CGFloat, multiplier : CGFloat = 1.0) -> UIView? 
{ 
    let c = NSLayoutConstraint(item: self, attribute: attribute, relatedBy: relation, toItem: nil, attribute: .NotAnAttribute, multiplier: multiplier, constant: constant) 
    self.addConstraint(c) 
    return self 
} 

}

Когда я пытался отладить иерархии просмотра, отладчик, единственный вид, который имел белый фон был Tableview, но я очистил фон в коде. Я также попытался установить backgroundView tableView в ноль, а также backgroundView.backgroundColor на clearColor(). Ничего не изменилось.

+0

Попробуйте изменить цвет фона стола TableView на задний план стола TableCellCell. –

+1

Это также не работает. Этот фон ниже по-прежнему белый. Я боюсь, что этот взгляд ниже на самом деле не tableView, а нечто, созданное с целью анимации. –

+0

hmm, ok, как только вы запустите приложение на симуляторе, вернитесь к Xcode Выберите «Отладка»> «Просмотр отладки»> «Захват» Иерархия, это откроется в Xcode, а затем выберите 4-й значок, похожий на куб, когда он станет сеткой, тогда вы можете получить 360-градусный обзор симулятора и посмотреть, какой вид именно он белый –

ответ

0

Возможно, попробуйте установить нижний колонтитул UITableView на пустой экран, не знаю, почему, но он швы, чтобы помочь в аналогичной проблеме, как у вас.

[_tableView setTableFooterView:[[UIView alloc] init]]; 
+0

Этот тоже не работает. –

Смежные вопросы