如何使我的图案视图在不拉伸的情况下延伸?

发布于 2024-11-13 05:23:06 字数 1897 浏览 0 评论 0原文

编辑 - 我已经弄清楚我最初做错了什么。我正在更改 UIScrollView 的大小,而不是模式子视图的大小。我已经解决了这个问题,但用它提出的新问题修改了我的问题。

我正在我的应用程序中制作一个带有横格纸效果的笔记部分。这些线条位于单独的 UIScrollView 上,该视图响应 scrollViewDidScroll:,因此线条和文本始终一起移动。我的行在 viewWillAppear 中设置如下:

CGRect noteLinesRect = CGRectMake(self.view.bounds.origin.x, 
                                  self.view.bounds.origin.y, 
                                  self.view.bounds.size.width, 
                                  noteTextView.contentSize.height+self.view.bounds.size.height);

UIScrollView *anoteXLinesView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.noteXLinesView = anoteXLinesView; 
[anoteXLinesView release];

LinePatternView *linesPattern = [[LinePatternView alloc] initWithFrame:noteLinesRect];
 self.linesPatternView = linesPattern; [linesPattern release];
[self.noteXLinesView addSubview:self.linesPatternView];
[linesPattern release];

CGPoint newOffset = CGPointMake(self.noteTextView.contentOffset.x, noteTextView.contentOffset.y - NOTE_LINES_OFFSET);
self.noteXLinesView.contentOffset = newOffset;

[self.view insertSubview:self.noteXLinesView atIndex:0];

当用户第一次查看存储的注释时,效果很好 - 所有文本都带有很好的下划线。但当他们写更多的文本时,最终他们会到达我在 viewWillAppear 中创建的行的底部,并在“白纸”上书写。所以我需要我的横格纸图案动态地变大和变小,所以它总是比我的textView的contentSize大一点。我试图这样做:

-(void)textViewDidChange:(UITextView *)textView
{
    self.linesPatternView.frame = CGRectMake( self.linesPatternView.frame.origin.x, //-self.noteTextView.contentOffset.y+NOTE_LINES_OFFSET, 
                                              self.linesPatternView.frame.origin.y, 
                                              self.linesPatternView.frame.size.width, 
                                              noteTextView.contentSize.height+self.view.bounds.size.height );
}

问题是,虽然横格纸图案的尺寸确实增加了,但它并没有在底部添加新的线条。相反,随着视图变大,图案会延伸并变大。我做错了什么?

EDIT - I've worked out what I was originally doing wrong. I was changing the size of the UIScrollView, instead of the pattern subview. I have fixed that, but amended my question with the new problem this has thrown up.

I am making a notes section in my app with a lined-paper effect. The lines are on a separate UIScrollView which responds to scrollViewDidScroll: so the lines and text always move together. My lines are set up like this in viewWillAppear:

CGRect noteLinesRect = CGRectMake(self.view.bounds.origin.x, 
                                  self.view.bounds.origin.y, 
                                  self.view.bounds.size.width, 
                                  noteTextView.contentSize.height+self.view.bounds.size.height);

UIScrollView *anoteXLinesView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.noteXLinesView = anoteXLinesView; 
[anoteXLinesView release];

LinePatternView *linesPattern = [[LinePatternView alloc] initWithFrame:noteLinesRect];
 self.linesPatternView = linesPattern; [linesPattern release];
[self.noteXLinesView addSubview:self.linesPatternView];
[linesPattern release];

CGPoint newOffset = CGPointMake(self.noteTextView.contentOffset.x, noteTextView.contentOffset.y - NOTE_LINES_OFFSET);
self.noteXLinesView.contentOffset = newOffset;

[self.view insertSubview:self.noteXLinesView atIndex:0];

This works fine when the user first looks at a stored note - all the text is nicely underlined. But when they write more text, eventually they get to the bottom of the lines I created in viewWillAppear and are writing on 'blank paper'. So I need my lined-paper pattern to dynamically get bigger and smaller so it is always a bit bigger than the contentSize of my textView. I am trying to do that like this:

-(void)textViewDidChange:(UITextView *)textView
{
    self.linesPatternView.frame = CGRectMake( self.linesPatternView.frame.origin.x, //-self.noteTextView.contentOffset.y+NOTE_LINES_OFFSET, 
                                              self.linesPatternView.frame.origin.y, 
                                              self.linesPatternView.frame.size.width, 
                                              noteTextView.contentSize.height+self.view.bounds.size.height );
}

The problem is, although the lined-paper pattern does increase in size, it doesn't add new lines at the bottom. Instead, the pattern stretches out and gets bigger as the view gets bigger. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懒猫 2024-11-20 05:23:06

解决方案之一是制作 3 个视图,每个视图包含屏幕上滚动视图框架大小的线条。您将这三个视图放置在滚动视图中另一个视图的下面,并通过其委托监视滚动视图。

向下滚动时,您会检查:

一旦最上面的一个超出屏幕超过 Y 像素,您就将其从滚动视图中删除并将其插入到底部的下面。

向上滚动时,您会检查:

一旦最底部的一个超出屏幕超过 Y 像素,您就将其从滚动视图中删除并将其插入到顶部的上方。

One of the solutions is to make 3 views, each containing the lines of the size of your scrollview frame on screen. You position the three one underneath the other in the scrollview and monitor the scrollview through its delegate.

When scrolling down you check:

As soon as the topmost one goes offscreen for more than Y pixels you remove it from the scrollview and insert it underneath the bottom one.

When scrolling up you check:

As soon as the bottommost one goes offscreen for more than Y pixels you remove it from the scrollview and insert it above the top one.

ぇ气 2024-11-20 05:23:06

您不简单地使用平铺图案作为背景视图的 backgroundColor 是有原因的吗? UIColor 的 +colorWithPatternImage: 可以让您设置一个背景,该背景将无限平铺,并且不会随着视图大小的调整而拉伸。如果背景的一部分必须不同(例如纸张的顶部),您可以将包含该背景的图像视图放置在背景视图的顶部。

Is there a reason you’re not simply using a tiled pattern as your background view’s backgroundColor? UIColor’s +colorWithPatternImage: will let you set a background that’ll tile indefinitely and won’t stretch as your view resizes. If part of the background has to be different—like the top of your paper, for instance—you can just place an image view containing that at the top of your background view.

清风疏影 2024-11-20 05:23:06

固定的!除了我对上述问题的编辑中概述的更改之外,我只需要在调整大小后调用 [self.linesPatternView setNeedsDisplay];

Fixed! In addition to the changes outlined in my edit to the question above, I just needed to call [self.linesPatternView setNeedsDisplay]; after the resize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文