Swift:使用子视图后滚动视图不起作用

时间:2018-07-10 12:40:19

标签: swift scrollview

我想以编程方式将子视图添加到scrollview

如果我将subviews添加到scrollview,则无法滚动

for subview in view.scrollView.subviews {
    subview.removeFromSuperview()
}

var j = 0
for value in getList {
    let viewChild = SelectClass.createMyClassView()
    viewChild.translatesAutoresizingMaskIntoConstraints = false
    viewAll[j] = viewChild

    viewChild.title.text = value.value

    view.scrollView.addSubview(viewChild)

    j = j+1
}

var i = 0
for subview in view.scrollView.subviews {
    let item = subview as? UIView
        NSLayoutConstraint.activate([
            (item?.leftAnchor.constraint(equalTo: view.scrollView.leftAnchor))!,
            (item?.rightAnchor.constraint(equalTo: view.scrollView.rightAnchor))!,
             (item?.heightAnchor.constraint(equalToConstant: 50))!
         ])

     if(i > 0){
         NSLayoutConstraint.activate([
             (item?.topAnchor.constraint(equalTo: (viewAll[i-1]?.bottomAnchor)!))!
         ])
     } else {
         NSLayoutConstraint.activate([
             (item?.topAnchor.constraint(equalTo: view.scrollView.topAnchor))!
         ])
     }

     i = i+1
}

view.scrollView.isScrollEnabled = true

我在scrollView中尝试了一种视图,但无法再使用

在正常情节提要中可以正常工作,但addSubView不能正常工作

我该如何解决?

1 个答案:

答案 0 :(得分:1)

首先最好使用function kl_rename_plugin_menus() { global $menu; // Define your changes here $updates = array( "bookacti_manage_booking_activities" => array( 'name' => 'Testname', 'icon' => 'dashicons-lock' ) ); foreach ( $menu as $k => $props ) { // Check for new values $new_values = ( isset( $updates[ $props[0] ] ) ) ? $updates[ $props[0] ] : false; if ( ! $new_values ) continue; // Change menu name $menu[$k][0] = $new_values['name']; // Optionally change menu icon if ( isset( $new_values['icon'] ) ) $menu[$k][6] = $new_values['icon']; } } add_action( 'admin_init', 'kl_rename_plugin_menus' ); ,在这里您需要为最后一项添加底部约束

UIStackView