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

具有居中 UIImageView 的 UIScrollView,如照片應用

UIScrollView with centered UIImageView, like Photos app(具有居中 UIImageView 的 UIScrollView,如照片應用)
本文介紹了具有居中 UIImageView 的 UIScrollView,如照片應用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想要一個帶有圖像內容視圖的滾動視圖.圖像實際上是比屏幕大得多的地圖.地圖最初應該位于滾動視圖的中心,就像您將 iPhone 轉為橫向時照片應用程序中的照片一樣.

I would like to have scroll view with an image content view. The image is actually map which is much bigger than the screen. The map should be initially in the center of the scroll view, like photos in Photos app when you turn iPhone to landscape orientation.

我沒有設法讓地圖同時正確縮放和滾動.假設地圖圖像從屏幕頂部開始(縱向),代碼如下所示:

I did not manage to have the map in the center with correct zooming and scrolling at the same time. Provided that the map image starts from the top of the screen (in portrait orientation), the code looks something like:

- (void)loadView {
    mapView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.jpg"]];
    CGFloat mapHeight = MAP_HEIGHT * SCREEN_WIDTH / MAP_WIDTH;
    mapView.frame = CGRectMake(0, 0, SCREEN_WIDTH, mapHeight);
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    scrollView.delegate = self;
    scrollView.contentSize = mapView.frame.size;
    scrollView.maximumZoomScale = MAP_WIDTH / SCREEN_WIDTH;
    scrollView.minimumZoomScale = 1;
    [scrollView addSubview:mapView];
    self.view = scrollView;
}

當我將圖像框架移動到中心時,圖像只會從其框架的頂部向下增長.我嘗試使用 mapView 轉換,動態更改 imageView 的框架.到目前為止,沒有什么對我有用.

When I move the image frame to the center, the image grows only from the top of its frame down. I tried to play around with mapView transform, with dynamically changing frame of the imageView. Nothing works for me so far.

推薦答案

這段代碼應該可以在大多數版本的 iOS 上運行(并且已經過測試可以在 3.1 以上版本上運行).

This code should work on most versions of iOS (and has been tested to work on 3.1 upwards).

它基于 Jonah 的回答中提到的 Apple WWDC 代碼.

It's based on the Apple WWDC code mentioned in Jonah's answer.

將以下內容添加到您的 UIScrollView 子類中,并將 tileContainerView 替換為包含您的圖像或圖塊的視圖:

Add the below to your subclass of UIScrollView, and replace tileContainerView with the view containing your image or tiles:

- (void)layoutSubviews {
    [super layoutSubviews];

    // center the image as it becomes smaller than the size of the screen
    CGSize boundsSize = self.bounds.size;
    CGRect frameToCenter = tileContainerView.frame;

    // center horizontally
    if (frameToCenter.size.width < boundsSize.width)
        frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
    else
        frameToCenter.origin.x = 0;

    // center vertically
    if (frameToCenter.size.height < boundsSize.height)
        frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
    else
        frameToCenter.origin.y = 0;

    tileContainerView.frame = frameToCenter;
}

這篇關于具有居中 UIImageView 的 UIScrollView,如照片應用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 一区二区三区四区国产 | 亚洲精品视频网站在线观看 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 精品一区av | 亚洲成人福利视频 | 免费视频二区 | 日韩国产一区二区三区 | 成人在线小视频 | 日韩高清黄色 | 欧洲一区二区视频 | 国产激情一区二区三区 | 国产成人福利在线 | 日韩国产一区二区三区 | 国产成人一区二区三区久久久 | 老司机免费视频 | 久久天堂网 | 雨宫琴音一区二区在线 | 国产日韩欧美一区 | 国产极品91 | 99久热在线精品视频观看 | 欧美区日韩区 | 97精品超碰一区二区三区 | 亚洲精彩免费视频 | 亚洲美女一区二区三区 | 日韩一区二区三区视频 | 日韩av免费看 | 日韩欧美黄色 | 国产精品久久久久久久久久久久久 | 成人高清在线 | 九色在线观看 | 毛片一区二区三区 | 久久久久久美女 | 香蕉久久a毛片 | 亚洲国产精品久久久久秋霞不卡 | 色网在线观看 | 午夜性色a√在线视频观看9 | 久久国产精品亚洲 | 日韩免费在线观看视频 | 91精品国产综合久久久久久丝袜 | 亚洲精品乱码久久久久久按摩 | 91最新入口 |