【发布时间】:2011-06-03 14:58:43
【问题描述】:
编辑 - 我已经找出了我最初做错了什么。我正在更改 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 );
}
问题是,虽然横格纸图案的尺寸确实增加了,但它并没有在底部添加新的线条。相反,随着视图变大,图案会延伸并变大。我做错了什么?
【问题讨论】:
标签: iphone cocoa-touch uiscrollview uitextview