【问题标题】:tableView is moving up more than the defined valuetableView 正在向上移动超过定义的值
【发布时间】:2016-06-18 07:20:25
【问题描述】:

我有TabBar 嵌入tableViewController 并且在我的单元格中我有一个textView 并且我正在尝试在textView's 编辑开始时向上移动tableView,这就是我这样做的方式:

func textViewDidBeginEditing(textView: UITextView) {

 if textView == descriptionTextView {

    let indexPath: NSIndexPath = NSIndexPath(forRow: 4, inSection: 0)
    self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Middle , animated: true)

    if textView.textColor == UIColor.lightGrayColor() {
        textView.text = nil
        textView.textColor = UIColor.blackColor()
    }
    }
}

它工作正常,但滚动不够流畅,它滚动了一些额外的点然后下降,这可能是因为 tabBars 的框架而发生的

为此,我尝试将内容设置为 inSet:

tableView.contentInset = (UIEdgeInsets(top: 0, left: 0, bottom: -30, right: 0))

但还是有同样的问题

编辑开始时从ScrollViewDidScroll 中查看contentOffSet.y 的值:

tableView is Moving : 236.5
tableView is Moving : 247.5
tableView is Moving : 254.0
tableView is Moving : 255.5
tableView is Moving : 190.0
tableView is Moving : 189.5
tableView is Moving : 189.0
tableView is Moving : 187.0
tableView is Moving : 185.0
tableView is Moving : 182.0
tableView is Moving : 178.5
tableView is Moving : 175.0
tableView is Moving : 171.0
tableView is Moving : 167.0
tableView is Moving : 163.0
tableView is Moving : 159.0
tableView is Moving : 155.0
tableView is Moving : 152.0
tableView is Moving : 149.0
tableView is Moving : 146.5
tableView is Moving : 144.5
tableView is Moving : 143.5
tableView is Moving : 143.0

您可以在上面看到,一开始是255.5,然后是143.0

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: uitableview uiscrollview swift2


    【解决方案1】:
      func textViewShouldBeginEditing(textView: UITextView) -> Bool{
    
     if textView == descriptionTextView {
    
        self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height - 190 )
        let indexPath: NSIndexPath = NSIndexPath(forRow: 4, inSection: 0)
       UIScrollView .beginAnimations("UP", context: nil)
                UIScrollView .setAnimationDuration(0.3)
                scrollView.contentOffset = CGPointMake(0, CGFloat(305
                    + 70 * CGFloat(isiphone6())))
                UIScrollView .commitAnimations()
    
    }
    

    请试试这个

    【讨论】:

    • 嘿@KaranJeet 感谢您的回复,这里的isiphone6 是什么?
    • 不要使用 cgfloaft(305 + 70 * cgfloat(Tisiphone 6))。这些是检查。只使用 cgpointmake(0,300(向上移动))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多