1

my app consists of a table view controller and a view controller. when i press a cell in the table view, the toolbar at that view slips with animation down outside the screen and when i'm in the view controller and press back, the toolbar bar slips upwards to it's original position. My problem is, i figured out a bug that when i'm in the view controller and press the home button to exit the app and then come back. the app resumes where i left but when i go back to the table view, the toolbar shifts upwards beyond it's original position. the sliding of the toolbar works fine when i'm in the app before exiting. so there's like something is being called to reset the toolbar to it's origin and thus adding the additional y-axis point to shift more upwards. does anybody know what are those methods?

Code:

i have this in the viewWillAppear method of the view controller:

[UIView animateWithDuration:0.7 animations:^{
        self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
    } completion:^(BOOL finished){
        self.navigationController.toolbar.hidden = YES;
    }];

and in the same view when it needs to disappear i added this in the viewWillDisappear:

[[self.navigationController toolbar] setHidden:NO];
    [UIView animateWithDuration:1 animations:^{
        self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y - self.navigationController.toolbar.frame.size.height);
    } completion:^(BOOL finished){
    }];

i tried this as another way to animate the hiding of the toolbar but there is no animation:

- (void) viewWillAppear:(BOOL)animated
{
    [self.picker setHidden:YES];


    [self.navigationController setToolbarHidden:YES animated:YES];

}

- (void) viewWillDisappear:(BOOL)animated
{


    [self.navigationController setToolbarHidden:NO animated:YES];


    [self.course setValue:self.nameTextField.text forKey:@"courseName"];
    [self.course setValue:[NSNumber numberWithInt:[self.creditsTextfield.text integerValue]] forKey:@"courseCredits"];
    [self.course setValue:[NSNumber numberWithInt:[self.chaptersTextfield.text integerValue]] forKey:@"courseChapters"];
    [self.course setValue:self.gradeTextfield.text forKey:@"courseGrade"];
}
4

3 回答 3

0

由于您使用的是属于 UINavigationController 的工具栏(而不是由您自己的控制器实例化并添加到 UIView 的独立 UIToolbar),因此最好使用 UINavigationController 公开的方法,因为您不知道它是如何管理和移动它的用户界面工具栏。

试着把它放在 viewWillAppear: 中,而不是整个动画块

[self.navigationController setToolbarHidden:NO animated:YES];

这在 viewWillDisappear 中:

[self.navigationController setToolbarHidden:YES animated:YES];
于 2013-04-03T21:49:46.533 回答
0

一方面,您应该使用框架而不是中心,但将 viewWillDisappear 动画行替换为:

self.navigationController.toolbar.frame = CGRectMake(0,0,self.navigationController.toolbar.frame.size.width, self.navigationController.toolbar.frame.size.height);

告诉我会发生什么...

那应该可以解决您的问题。

于 2013-04-03T21:34:30.497 回答
0

我修好了它!我在 viewWillDisappear 中添加了以下代码行:

 self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, 458);
    self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);

因为问题似乎是,当应用程序进入后台时,前台工具栏会重置为其原始位置,因此在导航回表格视图后,工具栏会移动到其原始位置之外。因此,我添加的第一行将工具栏重置为其原始位置,同时仍处于隐藏状态,然后将其向下移动。之后动画块就完成了。我这样做是为了让动画适用于以下情况: 1. 用户从表格视图进入详细视图,然后返回表格视图而不退出应用程序。2.用户从tableview进入detail view然后退出app,然后recovery app回到tableview。

于 2013-04-03T23:19:05.407 回答