2017-01-31 3 views
0

Je suis nouveau dans iOS programming.Taille de UIView et UITextView programme dans iOS Objective-C

Dans mon application (ios + Objective-C + Auto resize) j'ai UITextView à l'intérieur de UIView. Initialement, la hauteur de UIView est de 50 et UITextView est de 30 en bas de l'écran. Ce que je veux faire est, je veux changer la hauteur des deux composants en tant que type d'utilisateur du texte, c'est-à-dire y et height des deux composants va changer.

J'utilise le code ci-dessous, mais sa ne fonctionne pas correctement.

- (void)textViewDidChange:(UITextView *)textView 
{ 
    CGFloat fixedWidth = textView.frame.size.width; 
    CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; 
    CGRect newFrame = textView.frame; 

    CGRect viewFrame = _viewMsg.frame; 
    viewFrame.origin.y = viewFrame.origin.y - (newSize.height - 30.0); 
    viewFrame.size.height = viewFrame.size.height + (newSize.height - 30.0); 
    _viewMsg.frame = viewFrame; 

    newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); 
    textView.frame = newFrame; 

} 

S'il vous plaît me expliquer comment le redimensionnement travail avec Auto Resize dynamiquement.

Répondre

0

Vous pouvez modifier comme ci-dessous le code

- (void)textViewDidChange:(UITextView *)textView 
{ 
    CGFloat fixedWidth = textView.frame.size.width; 
    CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; 
    CGRect newFrame = textView.frame; 
    newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); 
    textView.frame = newFrame; 


    CGRect viewFrame = _viewMsg.frame; 
    viewFrame.size.height = _viewMsg.frame.size.height; 
    viewFrame.origin.y= self.view-viewFrame.size.height-30; 
    _viewMsg.frame =viewFrame; 

} 

il me aider à augmenter votre vue & hauteur de textView.

+0

J'ai une erreur à 'viewFrame.origin.y = self.view-viewFrame.size.height-30;' –

+0

Où votre _viewMsg' est-il ajouté? cette vue que vous devez utiliser ici dans mon cas, je l'ai ajouté dans 'self.view'. – CodeChanger