1

固定的

事实证明动画被调用了两次。我现在已经修复了它,所以动画只被调用一次并且它工作得很好。


我怀疑这可能与我使用子视图控制器有关,但是当我尝试使用动画删除子视图控制器的视图时,我注意到一些奇怪的行为。

我将子视图控制器与子视图控制器的视图一起添加到父视图,并从屏幕底部为该视图设置动画。这非常有效——我的问题是当我尝试删除子视图/视图控制器时。我正在将孩子的视图动画到屏幕底部,然后调用[self.view removeFromSuperview]完成块,但视图会立即被删除(因此不会发生动画)。如果我删除该[self.view removeFromSuperview]行,动画将正常工作,但视图不会从父视图控制器的视图中删除。


添加子视图控制器

(这按预期工作)

ChildViewController *myChildViewController = [[ChildViewController alloc] init];
myChildViewController.view.frame = CGRectMake(0.f, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 64.f);

[self addChildViewController:myChildViewController];
[self.view addSubview:myChildViewController.view];
[myChildViewController didMoveToParentViewController:self];

[UIView animateWithDuration:0.75f delay:0.f usingSpringWithDamping:0.6f initialSpringVelocity:0.75f options:0 animations:^{
    myChildViewController.view.frame = CGRectMake(0.f, 64.f, self.view.frame.size.width, self.view.frame.size.height - 64.f);
} completion:nil];


删除子视图控制器

(这不起作用——视图被立即删除,而不是在完成后)

[UIView animateWithDuration:0.75f delay:0.f usingSpringWithDamping:0.6f initialSpringVelocity:0.75f options:0 animations:^{
    self.view.frame = CGRectMake(0.f, self.view.superview.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
    if (finished)
    {
        [self willMoveToParentViewController:self.parentViewController];
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
    }
}];



我什至尝试删除[self willMoveToParentViewController:self.parentViewController][self removeFromParentViewController]只是看看它是否改变了任何东西,但只要[self.view removeFromSuperview]存在,视图就会立即消失。

4

1 回答 1

0

在父类中添加

- (void) moveToAddJobVC:(NSString*)storyboardId {

    ChildViewController *destVC = [self.storyboard instantiateViewControllerWithIdentifier:storyboardId];
    destVC.completionHandler = ^(NSString* string) {
        NSLog(@"Returned strng.....%@",string);
        //[self viewWillAppear:YES];
    };
    [destVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self addChildViewController:destVC];
    [self.view addSubview:destVC.view];
    [destVC didMoveToParentViewController:self];

    [UIView animateWithDuration:0.3 animations:^{
        [destVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    }];

}

并在子 VC 中写

@property (nonatomic,copy) void (^completionHandler)(NSString *string);

- (IBAction)dismissBtnAction:(id)sender{

    if (self.completionHandler)
    {
        self.completionHandler(@"Return data");
    }
    [self removeFromParentViewController];
    [self.view removeFromSuperview];
}
于 2017-04-03T13:29:42.977 回答