[英]Add content dynamically to UIScrollView
So I think a UIScrollView is the best way to achieve what I want. 所以我认为UIScrollView是实现我想要的最好的方法。
I will be adding 1 pixel width lines to the right side of a view every 1 second. 我将每1秒在视图的右侧添加1个像素宽度的线。 I only want the last x number of lines shown on the screen, but then the ability to slide backwards and view previous ones.
我只希望屏幕上显示的最后x行数,然后才可以向后滑动并查看先前的行。
For an example of what the view will look like: 有关视图外观的示例:
From what I can tell I should use a UIScrollView to achieve this, but it seems that that wants you to define the width and number to render ahead of time, but I will be adding it dynamically while the user is using my app. 据我所知,我应该使用UIScrollView来实现这一点,但是似乎要您定义要渲染的宽度和数字,但是我将在用户使用我的应用程序时动态地添加它。
Any help would be great, thanks! 任何帮助将是巨大的,谢谢!
I think using a scrollView will be pretty complicated. 我认为使用scrollView将非常复杂。 My suggestion is you could use a
collectionView
for that and use insertRowAtIndexPath:
to insert new rows. 我的建议是您可以为此使用
collectionView
并使用insertRowAtIndexPath:
插入新行。
You will implement the delegate method for the cell size, looking something like this : 您将实现像元大小的委托方法,如下所示:
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(1, CGRectGetHeight(collectionView.frame));
}
Then you just need to set different colors for the cells background. 然后,您只需要为单元格背景设置不同的颜色。
Let me know how it went or if you have questions. 让我知道进展如何,或者您有任何疑问。
检查此解决方案
CGFloat width = self.scrollView.bounds.size.width; CGFloat height = self.scrollView.bounds.size.height;//CGRectGetMaxY(textField.frame); self.scrollView.contentSize = CGSizeMake(width, height);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.