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

具有動態內容的 UIScrollView

UIScrollView with dynamic content(具有動態內容的 UIScrollView)
本文介紹了具有動態內容的 UIScrollView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試實現一個 UIScrollView,但那里的每個教程都處理預設數量的項目.

I'm trying to implement a UIScrollView, but every tutorial out there deals with a preset number of items.

我有多個 UITextField,但文本字段的數量各不相同.基本上,只要一個 textField 包含文本,另一個空的就會出現在其下方,允許用戶填寫無限數量的文本字段.

What I have are multiple UITextField's, but the number of textfields vary. Basically, as soon as one textField contains text, another empty one appears below it, allowing the user to fill in an unlimited number of textfields.

只要用戶在前一個文本字段中鍵入內容,我的代碼就會創建一個新文本字段.這個的x-coordinates和前一個一樣,但是新的y-coordinates等于前一個的高度+5px.

My code creates a new textfield as soon as the user types something into a previous one. The x-coordinatesof this is the same as the previous one, but the y-coordinatesto the new one equals the height of the previous + 5px.

我正在使用情節提要,并且我已將我的原始 textField 放在 UIScrollView 中.我已將此 scrollView 連接到我的代碼,并以這種方式添加一個新文本字段:[self.scrollView addSubview:newTextField];

I'm using storyboards, and I have placed my original textField within a UIScrollView. I have connected this scrollView to my code, and I add a new textfield this way: [self.scrollView addSubview:newTextField];

但是,當 textFields 的數量超過 scrollView 時,我無法滾動顯示新添加的內容.

However, when the amount of textFields exceeds the scrollView, I cannot scroll to reveal the new one that's been added.

我該怎么做呢?我認為我沒有完全理解 setContentSize 的東西,所以它可能與此有關.下面是一些圖片和代碼來解釋我的問題:

How would I go about doing this? I don't think I completely get the setContentSize thing, so it might have something to do with that. Here are some pictures and code to explain my problem:

添加新文本字段的代碼:

UITextField *newTextField = [[UITextField alloc]initWithFrame:CGRectMake(textField.frame.origin.x, textField.frame.origin.y + textField.frame.size.height+5, textField.frame.size.width, textField.frame.size.height)];
newTextField.placeholder = @"Add more text";
newTextField.borderStyle = UITextBorderStyleNone;
newTextField.font = [UIFont systemFontOfSize:14];
newTextField.autocorrectionType = UITextAutocorrectionTypeYes;
newTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
newTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
newTextField.returnKeyType = UIReturnKeyDone;
[newTextField setTag:textFieldTag];
newTextField.delegate = self;
[self.scrollView addSubview:newTextField];

故事板:

在這里你可以看到我是如何在滾動視圖中放置原始文本字段的

Here you can see how I have placed the original textfield within my scrollview

它在模擬器中的樣子:

當您在文本字段中輸入文本時,會發生這種情況:

一個空的文本域出現在前一個文本域的下方.

An empty textfield appears below the previous one.

但是,當您超出 ScrollView 時,就會發生這種情況

您無法再看到新的 textField,因為它位于 scrollView 的邊界之下.你也不能滾動顯示它.

You can no longer see the new textField because it is below the scrollView's boundaries. You can not scroll to reveal it either.

有誰知道如何解決這個問題?如果你有時間,你會如何讓滾動視圖自動向下滾動以顯示已添加的新文本字段?

Does anyone know how to solve this? And if you have time, how would you make it so the scrollview automatically scrolls down to reveal the new textfield that's been added?

非常感謝任何幫助!謝謝!

Any help is greatly appreciated! Thanks!

推薦答案

contentSize 需要是滾動視圖中包含的內容的大小.

The contentSize needs to be the size of content contained within the scroll view.

如果 contentSizebounds.size 寬,那么您可以左右滾動.如果 contentSizebounds.size 高,則可以上下滾動.

If the contentSize is wider than the bounds.size, then you can scroll left and right. If the contentSize is taller than the bounds.size, then you can scroll up and down.

您需要將 contentSize 設置為您希望包含在滾動視圖中的整個區域.

You need to set the contentSize to be the entire area you wish to contain within your scroll view.

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(textField.frame.origin.x, textField.frame.origin.y + textField.frame.size.height+5, textField.frame.size.width, textField.frame.size.height)];
textField.placeholder = @"Add more text";
textField.borderStyle = UITextBorderStyleNone;
textField.font = [UIFont systemFontOfSize:14];
textField.autocorrectionType = UITextAutocorrectionTypeYes;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
textField.returnKeyType = UIReturnKeyDone;
textField.tag = textFieldTag;
textField.delegate = self;

[self.scrollView addSubview:textField];

// Update the contentSize to include the new text field.
CGFloat width = self.scrollView.bounds.size.width;
CGFloat height = CGRectGetMaxY(textField.frame);
self.scrollView.contentSize = CGSizeMake(width, height);

注意事項:

  • 不要以 new 開頭變量或方法.它具有特殊含義,您會混淆其他 Objective-C 開發人員和/或編譯器.
  • textField.tag = …[textfield setTag:…]; 好像你喜歡其他地方的點語法,所以我改用那個.
  • 我假設您不希望滾動視圖左右平移,所以我將內容寬度固定到滾動視圖的寬度.
  • Don't start variables or methods with new. It has special meaning and you will confuse other Objective-C developers and/or the compiler.
  • textField.tag = … is the same as [textfield setTag:…]; You seem to like the dot syntax in other places, so I switched to that.
  • I'm assuming you don't want the scroll view to pan left and right, so I pinned the content width to the scroll view's width.

這篇關于具有動態內容的 UIScrollView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 可縮放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
主站蜘蛛池模板: 一级黄色毛片a | 精品一区二区三区电影 | 精品成人在线观看 | 黄网站涩免费蜜桃网站 | 免费av一区二区三区 | 欧美精品久久久久久 | 午夜在线免费观看 | 欧美午夜精品久久久久免费视 | h视频免费在线观看 | 国产aⅴ爽av久久久久久久 | 91精品国产91久久久久久最新 | 91精品久久久久久久久 | 日韩视频―中文字幕 | 涩涩视频在线看 | av黄色免费 | 91看片视频 | 国产精品久久久久久久久久久久 | 亚洲成人久久久 | 久久久精 | 波多野结衣一二三区 | 毛片大全| 欧美精品一区二区三区一线天视频 | 一区二区三区四区av | 一道本不卡视频 | 91久久北条麻妃一区二区三区 | 亚洲精品久久久久久久久久久久久 | 欧美成人黄色小说 | 九九久久国产精品 | 欧美日韩国产精品一区 | 羞羞视频网 | 天天干夜夜操 | 久久亚洲综合 | 秋霞在线一区 | 欧美一区视频在线 | 国产欧美一区二区三区免费 | 久久小视频 | 精品蜜桃一区二区三区 | 一级一级一级毛片 | 国产在线观看一区 | 日日噜噜噜夜夜爽爽狠狠视频, | 一区二区免费在线 |