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

iOS:自動布局導致 UIScrollView 不滾動

iOS: Autolayout causing UIScrollView to not scroll(iOS:自動布局導致 UIScrollView 不滾動)
本文介紹了iOS:自動布局導致 UIScrollView 不滾動的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經設置了一個 UIScrollView,我想用它來顯示水平布局的 12 個圖像(只有 8 個適合屏幕).在下圖中,您可以看到我遇到的問題(這使我的滾動視圖無法滾動)、我的約束和我在情節提要上添加的 UIScrollView:

I have set up a UIScrollView with which I want to display 12 images (only 8 fit on screen) laid out horizontally. In the following image you can see the problem I'm having (which makes my scroll view not scroll), my constraints and the UIScrollView which I have added on storyboard:

我在 -(void)viewDidLoad 上調用了以下方法,在這里我設置"了我的滾動視圖(itemList 是我的滾動視圖屬性,itemNames 是一個包含圖像名稱的數組):

I have called the following method on -(void)viewDidLoad, where I "set up"my scrollview (itemList is my scroll view property and itemNames a array with the images'names):

- (void)setupHorizontalScrollView
{
    self.itemList.delegate = self;
    [self.itemList setTranslatesAutoresizingMaskIntoConstraints:NO];

    [self.itemList setBackgroundColor:[UIColor blackColor]];
    [self.itemList setCanCancelContentTouches:NO];

    self.itemList.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    self.itemList.clipsToBounds = NO;
    self.itemList.scrollEnabled = YES;
    self.itemList.pagingEnabled = NO;

    NSInteger tot=0;
    CGFloat cx = 0;
    for (; ; tot++) {
        if (tot==12) {
            break;
        }

        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.itemNames objectAtIndex:tot]]];

        CGRect rect = imageView.frame;
        rect.size.height = 40;
        rect.size.width = 40;
        rect.origin.x = cx;
        rect.origin.y = 0;

        imageView.frame = rect;
        [self.itemList addSubview:imageView];
        cx += imageView.frame.size.width;
    }

    [self.itemList setContentSize:CGSizeMake(cx, [self.itemList bounds].size.height)];
}

我添加了 [self.itemList setTranslatesAutoresizingMaskIntoConstraints:NO];因為我在其他帖子上看到了這個建議,但不管有沒有它都不起作用.它起作用的唯一方法是如果我取消選中情節提要上的使用 AutoLayout,但這會將我用來作為導航欄的 UIImageView 移動到屏幕底部.我不知道該怎么辦了,感謝任何幫助:)

I have added the [self.itemList setTranslatesAutoresizingMaskIntoConstraints:NO]; because I saw this suggestion on other posts, but it doesn't work with or without it. The only way it works is if I uncheck use AutoLayout on the storyboard, but that moves the UIImageViewI use to look as a navigation bar to the bottom of the screen. I don't know what to do anymore, any help is appreciated :)

推薦答案

兩種解決方案:

  1. 創建可以同時滿足的不同約束(您必須進行編輯).我認為問題在于您的底部空間和頂部空間限制是相互排斥的.請刪除一個,然后重試.如果這對您來說很困難,請嘗試添加另一個 UIView 來包含 UIScrollView 以幫助管理您的約束,起初可能看起來很奇怪,但有時添加另一個視圖來包含您的view 實際上在每個級別都讓它變得更簡單.

  1. Create different constraints that can be satisfied simultaneously (you will have to edit). I think the problem is your bottom space and top space constraints are mutually exclusive. please remove one and try again. IF this is difficult for you, try adding another UIView to contain the UIScrollView to help manage your constraints, it might seem odd at first, but sometimes adding another view to contain your view actually makes it simpler at each level.

關閉自動布局,并將 UIImageView 的自動調整大小掩碼更改為您想要的.

Turn off Autolayout, and change the autoresize masks of your UIImageView to be what you wish.

這篇關于iOS:自動布局導致 UIScrollView 不滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 农村妇女毛片精品久久久 | 999精品在线 | 国产激情视频在线观看 | 亚洲iv一区二区三区 | 成人精品福利 | 69福利影院 | 国产在线拍偷自揄拍视频 | 欧美一区二区三区视频在线播放 | 国产成人午夜精品影院游乐网 | 九九精品久久久 | 久久精品国产一区二区三区 | 精品亚洲一区二区三区 | 国产精品一区二区久久 | 久久久精品影院 | 精品欧美一区二区三区久久久 | 国产日韩欧美一区 | 亚州av | 丝袜一区二区三区 | 91av国产在线视频 | 桃色五月 | 成人在线小视频 | 欧美日韩在线观看一区 | 一二三区视频 | 香蕉视频91 | 亚洲一区二区av在线 | 激情网五月天 | 日韩电影一区二区三区 | 国产精品一区二区福利视频 | 久久蜜桃av一区二区天堂 | 日本一区二区三区视频在线 | 国产1区2区| 国产一级在线 | 欧美久久久久久 | 国产黄色在线观看 | 欧美不卡视频 | 国产精品18久久久 | 7777在线视频| 99成人| 3级毛片 | 久久一热| 日日夜夜免费精品 |