IOS父子帧更改问题

时间:2013-12-19 12:07:04

标签: ios uitextview frame

我正在尝试调整UITextView底部对齐的大小及其父视图,下面是我的代码:

-(void)textViewDidChange:(UITextView *)textView
{
CGSize newTextViewSize = [textView sizeThatFits:CGSizeMake(kTextViewFixedWidth, kTextViewMaxHeight)];

if( newTextViewSize.height != self.textViewOldHeight )
{

    CGRect newTextViewFrame = textView.frame;

    newTextViewFrame.size = CGSizeMake(fmaxf(newTextViewSize.width, kTextViewFixedWidth), newTextViewSize.height);

    CGPoint sizeDiff = CGPointMake(newTextViewFrame.size.width-textView.frame.size.width, newTextViewFrame.size.height-textView.frame.size.height);
    newTextViewFrame.origin = CGPointMake(textView.frame.origin.x, textView.frame.origin.y-sizeDiff.y);


    self.textViewOldHeight = newTextViewFrame.size.height;

    CGRect newViewFrame = self.frame;
    newViewFrame.origin = CGPointMake(self.frame.origin.x, self.frame.origin.y-sizeDiff.y);
    newViewFrame.size = CGSizeMake( self.frame.size.width, self.frame.size.height+sizeDiff.y);
    self.frame = newViewFrame;

    textView.frame = newTextViewFrame;


}

这里我尝试做的是计算textView的大小更改,然后将该更改应用于查看其父级 - 这是自我的。会发生什么是自我调整大小但textView重置。然而,当我赞扬发生自我调整的部分时,儿童textview按预期工作。任何人都可以指引我找到正确的方向,找到这里的错误吗?

谢谢,玩得开心......

在调查案例时,我编写了以下代码:

-(void)resize
{
    self.subView = ((UIView*)[self.subviews objectAtIndex:0]);

    [UIView animateWithDuration:2.0
                      delay:0.0 options:UIViewAnimationOptionCurveEaseOut
                 animations:^{

                         CGRect newSubViewFrame = self.subView.frame;
                         newSubViewFrame.size.height += 100;
                         self.subView.frame = newSubViewFrame;
                         NSLog(@"%f", self.subView.frame.size.height);

                         } completion:^(BOOL finished) {
                         [UIView animateWithDuration:2.0
                                               delay:0.0
                                             options:UIViewAnimationOptionCurveEaseOut
                                          animations:^{
                                              NSLog(@"%f", self.subView.frame.size.height);
                                              CGRect newSuperViewFrame = self.frame;
                                              newSuperViewFrame.origin.y -= 50;
                                              newSuperViewFrame.size.height += 100;
                                              self.frame = newSuperViewFrame;
                                              NSLog(@"%f", self.subView.frame.size.height);

                                          } completion:^(BOOL finished) {

                                          }];
                 }];
    NSLog(@"%f", self.subView.frame.size.height);
}

故事是我有一个超级(红色)和子视图(黑色),当代码运行时,子视图首先按照我的意图增长。但是当超级视图开始调整子视图大小时会重置其大小并记录所有返回的150.所以任何想法如何修复它?

Red is superview black is child

0 个答案:

没有答案