当文本视图作为第一响应者辞职时失去视图(失去焦点)

时间:2015-09-24 23:17:50

标签: ios objective-c

下面的代码在文本字段辞职时移动视图,但是当我将其更改为使用文本视图时,我在指示的行上出现错误。

-(void)textViewDidEndEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.3];
    [UIView setAnimationBeginsFromCurrentState:TRUE];
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y  200., self.view.frame.size.width, self.view.frame.size.height);//throws error Expected ')'

    [UIView commitAnimations];
}

有人能发现错误来源吗? (对于记录,textViewDidBeginEditing:非常相似的代码不会引发错误。)

以下也不会导致错误:

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.3];
    [UIView setAnimationBeginsFromCurrentState:TRUE];
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -200., self.view.frame.size.width, self.view.frame.size.height);

    [UIView commitAnimations];
}

1 个答案:

答案 0 :(得分:1)

你忘了一个加号!

self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y  200., self.view.frame.size.width, self.view.frame.size.height);

应该是:

self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + 200., self.view.frame.size.width, self.view.frame.size.height);

如果没有加号,编译器会看到self.view.frame.origin.y200,但不知道如何处理它们。 +告诉它将它们添加到一起并将结果传递给函数。