UITextView动画视图后的内容偏移量不足
问题描述:
我有一个位于视图底部的UITextView。当用户点击它时,我需要动画视图150px。我使用的是:UITextView动画视图后的内容偏移量不足
- (void)textViewDidBeginEditing:(UITextView *)textView{
和
- (void)textViewDidEndEditing:(UITextView *)textView{
,使这个。
在iOS5上,它工作正常。但是在iOS 4.3上,当视图是动画时,这个UITextView中的内容只有几个像素。
截图:http://cl.ly/1q3e0W2G1M000u1U3w1f
有人有类似的问题?
代码:
- (void)textViewDidBeginEditing:(UITextView *)textView{
if([textView.text isEqualToString:@"Placeholder text"]){
textView.text = @"";
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 150.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
if([textView.text isEqualToString:@""]){
textView.text = @"Placeholder text";
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 150.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
答
您需要的时候在textViewDidBeginEditing方法和之后的动画调用方法完成重置文本视图内容的插图......
试试这个代码:
- (void)textViewDidBeginEditing:(UITextView *)textView{
[textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
答
我发现,公认的答案引起一些视觉不规则。以下对我来说效果更好。
textView.contentMode = UIViewContentModeTop;
把这段代码放在哪里? – dormitkon
谢谢!你也可以使用常量'UIEdgeInsetsZero' – colincameron