2016-09-13 4 views
0

このチュートリアルで示すように、スタティックセルテーブルビューで伸縮性のある自己調整イメージを作成するにはどうすればよいですか? http://blog.matthewcheok.com/design-teardown-stretchy-headers/スクロール時にスタティックセルテーブルビューで伸縮性のあるイメージを作成する方法

ダイナミックセルではなくスタティックセルの場合。

編集:

class ProfileViewController2: UITableViewController { 

    var profilePic = "WilsonLer" 
    private let kTableHeaderHeight: CGFloat = 189 
    var headerView: UIView! 

    @IBOutlet weak var topHeader: UITableViewCell! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     let user = FIRAuth.auth()?.currentUser 
     self.navigationItem.title = user!.email 

     headerView = topHeader 
     tableView.contentInset = UIEdgeInsets(top: kTableHeaderHeight, left: 0, bottom: 0, right: 0) 
     tableView.contentOffset = CGPoint(x: 0, y: -kTableHeaderHeight) 
     updateHeaderView() 



     // to set and display profile image 
     let profilePicImage = topHeader.viewWithTag(1) as! UIImageView 
     let profilePicBG = topHeader.viewWithTag(2) as! UIImageView 
     profilePicImage.image = UIImage(named: profilePic) 
     profilePicBG.image = UIImage(named: profilePic) 
     profilePicImage.layer.cornerRadius = profilePicImage.frame.height/2 
     profilePicImage.clipsToBounds = true 
     profilePicImage.layer.borderWidth = 1 
     profilePicImage.layer.borderColor = UIColor.whiteColor().CGColor 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func updateHeaderView() { 

     var headerRect = CGRect(x: 0, y: -kTableHeaderHeight, width: tableView.bounds.width, height: kTableHeaderHeight) 
     if tableView.contentOffset.y < -kTableHeaderHeight { 

      headerRect.origin.y = tableView.contentOffset.y 
      headerRect.size.height = -tableView.contentOffset.y 

     } 
     topHeader.frame = headerRect 

    } 

    override func scrollViewDidScroll(scrollView: UIScrollView) { 
     updateHeaderView() 
    } 



} 

私は、リンクではなく、まだ無駄にする方法を試みました。セルのサブクラスを作成しようとしましたが、ダイナミックセルでのみ機能します。それは同じように動作します

enter image description here

おかげ

答えて

1

これは私が非スクロールヘッダーで得たすべてでした。画像はヘッダーです。ダイナミックまたは静的な細胞とは何の関係もありません。あなたがそれをテストしたい場合は、単純に1空白のスタティックセルを追加するには、UIImageヘッダー&ヘッダーのコードを追加します。それは正常に動作するはずです。

注:スタティックセルでは、セルごとにカスタムクラスを作成する必要があります。

注2:次回は、少なくとも次のような質問をしてみてください。 &人にあなたの仕事を依頼することを期待しないでください。

+0

すでに試してみましたが役に立たない –

+0

セルごとにカスタム*クラス*が必要なわけではありませんが、残りの部分はチェックアウトされます。 – NRitH