Code for implementing stretching at the top of IOS (Swift) page, iosswift

Source: Internet
Author: User

Code for implementing stretching at the top of IOS (Swift) page, iosswift

// Lazy loading
// Lazy var headView: MyHeaderView need to be stretched at the top of the custom view lazy var headView: MyHeaderView = {// let hframe = CGRect (x: 0, y: 0, width: swidth, height: swidth/self. imgRation) // let hview = Bundle. main. loadNibNamed ("MyInfoHeaderView", owner: nil, options: nil )?. First! MyInfoHeaderView // return hview;} () // MARK: 1) set view self. collectionView ?. AddSubview (self. headView)
Override func collectionView (_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)-> UICollectionViewCell {if indexPath. section = 0 {// return an empty cell let cell = collectionView at the top. dequeueReusableCell (withReuseIdentifier: reuseIdentifier, for: indexPath) return cell }.... func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, siz EForItemAt indexPath: IndexPath)-> CGSize {if indexPath. section = 0 {// return CGSize (width: swidth, height: 200.0 )}.... // MARK: List View self. tableView ?. AddSubview (self. headView)
Override func tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath)-> UITableViewCell {if indexPath. section = 0 {// return an empty cell var cell = tableView at the top. dequeueReusableCell (withIdentifier: reuseIdentifier) return cell! }.... Override func tableView (_ tableView: UITableView, heightForRowAt indexPath: IndexPath)-> CGFloat {if indexPath. section = 0 {return 200.0 ;}.... // MARK: override func scrollViewDidScroll (_ scrollView: UIScrollView) {let point = scrollView. contentOffset; if point. y <= 0 {// drop-down // self. headView. frame. size. height = swidth/imgRation-point. y // self. headView. frame. size. width = self. headView. frame. size. height * imgRation // self. headView. frame. origin. x = (swidth-self. headView. frame. size. width)/2 // self. headView. frame. origin. y = point. y // self. headView. titleImgLeft. constant = 18-self. headView. frame. origin. x // self. mainNavView. backgroundColor = UIColor. clear // self. mainNavView. searImg. image = UIImage (named: "search box r")} else {// push up // if point. y> = (self. headView. frame. height-64) {// self. mainNavView. searImg. image = UIImage (named: "search box w") // self. mainNavView. searchText. backgroundColor = UIColor. white //} // self. headView. titleImgLeft. constant = 18 // self. mainNavView. backgroundColor = UIColor (red: 245/255. 0, green: 74/255. 0, blue: 48/255. 0, alpha: point. y/(self. headView. frame. height-64 ))}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.