点击UITabBarController时滚动到顶部

时间:2018-08-14 10:15:35

标签: ios uitableview uitabbarcontroller

我有UITabBarController,其中一个选项卡具有两个容器视图,并且我想滚动到其中的两个控制器的顶部。

我的基本视图控制器为NotificationViewController,子视图控制器为NotificationNetworkViewControllerNotificationPodcastViewController

我正在使用以下扩展名:-

extension NotificationNetworkViewController: UITabBarControllerDelegate {
    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        print("Network TAB INDEX : \(tabBarController.selectedIndex)")
        notificationTable.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
    }
}

1 个答案:

答案 0 :(得分:1)

使用以下代码来满足您的需求。对于动画,您只需要在setContentOffset(_:animated:)函数的动画中传递值true / false。 希望这会对您有所帮助!

要滚动顶部而不显示动画

UIScrollView

要在动画顶部滚动

df <- df[order(df[,1], decreasing = T),]
df[duplicated(df[,2])==F,]

     A   B  
[1,] "1" "A"
[2,] "1" "B"
[3,] "0" "C"