我为我的应用编写了一个自定义segue,它部分模糊了源视图控制器。 segue工作正常,我得到了预期的效果。当我按下按钮将segue展开回源控制器时,应用程序崩溃了。我在各种方法中放了一些日志语句但没有调用任何内容,所以我认为我已经错误地查看了这些视图。这是segue代码:
- (void)perform {
NSLog(@"performing!");
UIView *sourceView = ((UIViewController *)self.sourceViewController).view;
UIView *destView = ((UIViewController *)self.destinationViewController).view;
UIViewController *sourceController = ((UIViewController *)self.sourceViewController);
if (!_rewinding) {
[sourceView.window insertSubview:destView aboveSubview:sourceView];
destView.center = CGPointMake(sourceView.frame.size.width * 1.5, sourceView.center.y);
}
CGPoint newSourceCenter = CGPointMake(sourceView.frame.origin.x - sourceView.frame.size.width * 0.4, sourceView.center.y);
CGPoint newDestCenter = CGPointMake(sourceView.center.x + sourceView.frame.size.width * 0.1, sourceView.center.y);
[UIView animateWithDuration:1.4
animations:^{
if (_rewinding) {
NSLog(@"rewind in segu");
destView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, destView.center.y);
sourceView.center = CGPointMake([UIScreen mainScreen].bounds.size.width*1.5, sourceView.center.y);
destView.alpha = 1.0;
} else {
destView.center = newDestCenter;
sourceView.center = newSourceCenter;
sourceView.alpha = 0.5;
}
} completion:^(BOOL finished) {
if (_rewinding)
NSLog(@"completed animation");
}];
}
一些照片展示了会发生什么。在点击单元格时,详细视图从右侧屏幕向左滑动,源视图也向左滑动。
我已尝试使用[source presentViewController:dest]
,但这样做会从窗口中删除源视图。由于我部分模糊了源,它必须在动画后留在屏幕上。设置它的正确方法是什么?
编辑: 启用僵尸后,我在日志中得到了这个。这对应于destinationViewController。所以很明显它在segue期间没有被保留。
[58880:c07] *** -[UIStoryboardUnwindSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x1f3c7fe0
答案 0 :(得分:1)
我将用我最终做的事来回答这个问题,但请保持开放,因为我非常感兴趣一种方法来做一个将原始视图留在屏幕上的部分。
我的快速解决方案是在原始视图控制器中处理所有动画。我认为这涵盖了上述所有与内存相关的问题,但可能不正确,因此请自担风险。
- (void)showModalDetailView {
NSLog(@"show modal");
if (!self.detailViewController) {
self.detailViewController = (SegmentDetailViewController *)[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"segDetail"];
self.detailViewController.view.center = CGPointMake(self.view.frame.size.width * 1.5, self.view.center.y);
[self.view.superview addSubview:self.detailViewController.view];
self.detailViewController.delegate = self;
}
CGPoint newSourceCenter = CGPointMake(self.view.frame.origin.x - self.view.frame.size.width * 0.4, self.view.center.y);
CGPoint newDestCenter = CGPointMake(self.view.center.x + self.view.frame.size.width * 0.1, self.view.center.y);
[UIView animateWithDuration:1.4
animations:^{
if (self.shouldRewind) {
self.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.view.center.y);
self.detailViewController.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width*1.5, self.detailViewController.view.center.y);
self.view.alpha = 1.0;
self.shouldRewind = NO;
self.detailViewController = nil;
} else {
self.detailViewController.view.center = newDestCenter;
self.view.center = newSourceCenter;
self.view.alpha = 0.5;
self.shouldRewind = YES;
}
} completion:^(BOOL finished) {
NSLog(@"animation complete");
}];
}