ios - swift : 在UITableView的headerView中加入一个UIScrollView,滚动不了?
PHP中文网
PHP中文网 2017-04-18 09:15:54
0
1
448

还有图片顶到状态栏了,设置headerView的frame.y = 64 ,没起作用


class TableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setUpHeaderView()
        setUpAdScrollView()
    }

    //MARK : 表头视图
    func setUpHeaderView() {
        let headView = UIImageView()
        headView.frame = CGRect(x: 0, y: 64, width: self.view.frame.width, height:250)
        headView.backgroundColor = UIColor.lightGrayColor()
        self.tableView.tableHeaderView = headView
    }

    func setUpAdScrollView() {
        let adSCView = UIScrollView()
        adSCView.delegate = self
        
        adSCView.frame = (self.tableView.tableHeaderView?.frame)!
        adSCView.contentSize = CGSize(width: 3 * adSCView.frame.width,height: adSCView.frame.height)
        
        /** 添加轮播图片 */
        //创建图片按钮
        for i in 0 ..< 3 {
            
            let adBtn = UIButton()
            adBtn.frame = CGRect(x: CGFloat(Float(i)) * adSCView.frame.width,y: 0,width: adSCView.frame.width,height: adSCView.frame.height - 20)
        
            adBtn.setImage(UIImage(named: String(format: "ad0%d",i + 1)), forState: UIControlState.Normal)
            
            adSCView.addSubview(adBtn)
        }
        /** 补充设置 */
        adSCView.backgroundColor = UIColor.yellowColor()
        //边缘不弹跳 整页滚动 不出现水平提示
        adSCView.bounces = false
        adSCView.pagingEnabled = true
        adSCView.showsHorizontalScrollIndicator = true
        adSCView.showsVerticalScrollIndicator = true
        
        self.tableView.tableHeaderView?.addSubview(adSCView)
    }

    
    
    
}

百度云连接 http://pan.baidu.com/s/1gf37EEn

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
PHPzhong

Your headerView 是个 UIImageView , which turns off click events by default:

self.tableView.tableHeaderView.userInteractiveEnabled = true;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template