所以我的应用程序包含一个滚动视图,其中有一个文本视图。用户可以选择添加图像,这样做时 UIImageView 子类会添加到滚动视图中。发生这种情况时,UITextView 应该向下移动以让开,但它不会这样做。我的代码如下:
// add a subview to the scroll view; push text field down
textEditorImageView *imageSubview = [[textEditorImageView alloc] initWithFrame:self.scrollView.frame];
2013-07-15 12:36:41.652 iCloud Test[3600:c07] Scroll view: {{20, 87}, {280, 345}}
2013-07-15 12:36:41.653 iCloud Test[3600:c07] Image subview: {{20, 87}, {280, 345}}
[self.scrollView addSubview:imageSubview];
imageSubview.image = image; // this is where the frame of the image subview is set
2013-07-15 12:36:41.653 iCloud Test[3600:c07] Image subview after setting frame: {{0, 0}, {280, 69}}
2013-07-15 12:36:41.654 iCloud Test[3600:c07] Main text field before setting frame: {{0, 0}, {280, 345}}
self.mainTextField.frame = CGRectMake(self.mainTextField.frame.origin.x, self.mainTextField.frame.origin.y + imageSubview.frame.size.height, self.mainTextField.frame.size.width, self.mainTextField.frame.size.height); // does not work. I tried setting the origin to random numbers but the text view stays at the same position.
2013-07-15 12:36:41.655 iCloud Test[3600:c07] Main text field after setting frame: {{0, 69}, {280, 345}}
[self.scrollView setNeedsDisplay]; // does not work with or without this
我的代码缺少什么?提前致谢!
编辑:为每行后的帧添加 NSLogs