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

具有居中 UIImageView 的 UIScrollView,如照片應(yīng)用

UIScrollView with centered UIImageView, like Photos app(具有居中 UIImageView 的 UIScrollView,如照片應(yīng)用)
本文介紹了具有居中 UIImageView 的 UIScrollView,如照片應(yīng)用的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我想要一個(gè)帶有圖像內(nèi)容視圖的滾動(dòng)視圖.圖像實(shí)際上是比屏幕大得多的地圖.地圖最初應(yīng)該位于滾動(dòng)視圖的中心,就像您將 iPhone 轉(zhuǎn)為橫向時(shí)照片應(yīng)用程序中的照片一樣.

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.

我沒(méi)有設(shè)法讓地圖同時(shí)正確縮放和滾動(dòng).假設(shè)地圖圖像從屏幕頂部開(kāi)始(縱向),代碼如下所示:

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;
}

當(dāng)我將圖像框架移動(dòng)到中心時(shí),圖像只會(huì)從其框架的頂部向下增長(zhǎng).我嘗試使用 mapView 轉(zhuǎn)換,動(dòng)態(tài)更改 imageView 的框架.到目前為止,沒(méi)有什么對(duì)我有用.

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.

推薦答案

這段代碼應(yīng)該可以在大多數(shù)版本的 iOS 上運(yùn)行(并且已經(jīng)過(guò)測(cè)試可以在 3.1 以上版本上運(yùn)行).

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.

將以下內(nèi)容添加到您的 UIScrollView 子類(lèi)中,并將 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;
}

這篇關(guān)于具有居中 UIImageView 的 UIScrollView,如照片應(yīng)用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 神马影院一区二区三区 | 自拍偷拍亚洲欧美 | 欧美视频1区 | 日韩毛片| 色综合久久伊人 | 一区二区三区精品视频 | 国产亚洲网站 | 91超碰在线| 久久久久无码国产精品一区 | 国产农村妇女精品一区 | 久久久久久亚洲精品 | 国产精品免费av | 免费在线观看一区二区 | 欧美日韩久久 | 欧美视频免费在线 | 米奇7777狠狠狠狠视频 | 91麻豆精品国产91久久久久久久久 | 精品小视频 | 成人免费小视频 | 日韩国产免费观看 | 日本一区二区不卡视频 | 国产一区免费 | 国产精品一区二区在线免费观看 | 亚洲精选一区 | www.国产一区| 一级片毛片 | 欧美性一区二区三区 | 久久国产精品99久久久久久丝袜 | 日韩欧美三级电影在线观看 | 夜夜爽99久久国产综合精品女不卡 | 久久久久久亚洲 | 国产欧美综合在线 | 亚洲国产专区 | 国产成人精品一区二三区在线观看 | 亚洲精品国产精品国自产在线 | 久久日韩精品 | 欧美区在线 | 日日天天 | 欧美专区在线 | 不卡欧美| 国产视频一区二区三区四区五区 |