久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

向下滾動時 ImageView 縮放

ImageView Scaling when scrolling down(向下滾動時 ImageView 縮放)
本文介紹了向下滾動時 ImageView 縮放的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

向下滾動時如何使用 autolayout 簡單地縮放 imageView ?

How can I simply scaling imageView with autolayout when scrolling down ?

嘗試查看視差效果,但不是我想要的.

Try to see parallax effect but not exactly what I wanted.

我只想使用一個 scrollView 和一個標題 ImageView 可以調整大小取決于 scrollView 位置.

I just want to use a scrollView and a header ImageView who can resize depends on scrollView position.

推薦答案

一步一步:

1 - 打開故事板并在頂部添加具有這些約束的圖像視圖(選擇您的縱橫比):

1 - open storyboard and add an image view on top with these constraint (choose your aspect ratio) :

2 - 為你的 uiimage 選擇 aspectFill 模式和 clipSubviews

2 - select aspectFill mode and clipSubviews for your uiimage

3 - 在 vi??ewController 的頂部添加一個 UIScrollView,里面有一個子視圖.有關使用 scrollView 的自動布局的所有詳細信息:http://natashatherobot.com/ios-autolayout-scrollview/

3 - add a UIScrollView on top of your viewController with a child view inside. All the details about the auto layout with scrollView : http://natashatherobot.com/ios-autolayout-scrollview/

4 - 然后在代碼中引用您的 imageView 和 scrollView.

4 - then make outlets reference of your imageView and scrollView in your code.

5 - 在 vi??ewDidLoad 中,插入self.automaticallyAdjustsScrollViewInsets = false 并設置 scrollView 的 contentInsets 和 contentOffset :

5 - in viewDidLoad, insert self.automaticallyAdjustsScrollViewInsets = false and set contentInsets and contentOffset of the scrollView :

class ViewController: UIViewController {

    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var imageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.automaticallyAdjustsScrollViewInsets = false
   }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        let imageHeight = imageView.frame.height

        let newOrigin = CGPoint(x: 0, y: -imageHeight)

        scrollView.contentOffset = newOrigin
        scrollView.contentInset = UIEdgeInsets(top: imageHeight, left: 0, bottom: 0, right: 0)
    }

}

6 - 將 scrollviewDelegate 添加到 ViewController 和 scrollViewDidScroll 方法以獲取 scrollView 的位置

6 - add scrollviewDelegate to the ViewController and the scrollViewDidScroll method to get position of the scrollView

class ViewController: UIViewController, UIScrollViewDelegate

override func viewDidLoad() {
        super.viewDidLoad()

        scrollView.delegate = self
        self.automaticallyAdjustsScrollViewInsets = false
}

func scrollViewDidScroll(scrollView: UIScrollView) {

    let offsetY = scrollView.contentOffset.y

    if offsetY < 0
    {
        imageView.frame.size.height = -offsetY
    }
    else
    {
        imageView.frame.size.height = imageView.frame.height
    }
}

7 - 然后構建并運行.

7 - then build and run.

您可以在 github 上下載示例:https://github.com/raphrel/scalingImageWhenScrollDown

you can download example on github: https://github.com/raphrel/scalingImageWhenScrollDown

也許有更好的解決方案,但這個可行.享受

there is maybe a better solution but this one works. enjoy

這篇關于向下滾動時 ImageView 縮放的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的邊緣工作) - IT屋-程序員軟件開發技術分享社
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的邊界自動更改,帶有內容插圖)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干擾按鈕.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滾動)
主站蜘蛛池模板: 福利在线观看 | 影视先锋av资源噜噜 | 成人性视频免费网站 | 久久久精品网 | 久久精品国产免费高清 | 国产精品69毛片高清亚洲 | 欧美日韩国产一区二区三区 | av中文字幕在线播放 | 久久99精品久久久久久青青日本 | 麻豆精品国产91久久久久久 | 国产高清视频在线播放 | 一区二区日韩 | 7777久久| 国产男女猛烈无遮掩视频免费网站 | 国产91在线 | 欧美 | 超碰精品在线 | 精品综合视频 | 亚洲国产精品激情在线观看 | 国产亚洲一区精品 | 国产一级免费视频 | 一区二区三区日韩 | 三级av免费| 免费精品视频在线观看 | 青青久草| 亚洲日日 | 国产亚洲一区二区三区 | 观看av| 亚洲福利一区 | 天天操人人干 | 久久国产精品色av免费观看 | 亚州中文字幕 | av电影手机在线看 | 国产高清在线 | 国产一区二区在线看 | 97精品超碰一区二区三区 | www.久久99| 午夜天堂精品久久久久 | 亚洲一区成人 | 国产精品久久久久aaaa九色 | 精品欧美乱码久久久久久 | 欧美日韩久久久 |