Ios7 iOS 7.1中的模式自定义段在被解除时发出警告 出身背景
我做了一个自定义的序列,允许“叠加卡”从顶部滑下,然后在被解雇时飞走。在编写代码时,我意识到所有示例都使用了Ios7 iOS 7.1中的模式自定义段在被解除时发出警告 出身背景,ios7,uiviewcontroller,uistoryboard,segue,modalviewcontroller,Ios7,Uiviewcontroller,Uistoryboard,Segue,Modalviewcontroller,我做了一个自定义的序列,允许“叠加卡”从顶部滑下,然后在被解雇时飞走。在编写代码时,我意识到所有示例都使用了UIViewControllerTransitioningDelegate来捕获segue被动画化/取消的时间。到目前为止还不错,但我发现的所有示例都让presentingController充当代理,这听起来很奇怪,因为我需要在两个地方“分发”我的“叠加卡”的逻辑;自定义序列和显示控制器 因此,我想我可以把两者结合在一起;自定义segue会使我的故事板更加整洁,因为我想显示为“叠加卡”的
UIViewControllerTransitioningDelegate
来捕获segue被动画化/取消的时间。到目前为止还不错,但我发现的所有示例都让presentingController
充当代理,这听起来很奇怪,因为我需要在两个地方“分发”我的“叠加卡”的逻辑;自定义序列和显示控制器
因此,我想我可以把两者结合在一起;自定义segue会使我的故事板更加整洁,因为我想显示为“叠加卡”的所有视图控制器都被分配了我创建的“CardSegue”,而不是让每个呈现控制器实现UIViewControllerTransitioningDelegate
问题
从其中一个呈现控制器,我在解除呈现的“叠加卡”时收到警告
我环顾四周,我所能找到的只是另一个似乎很有前途的职位;
但是,问题是,由于我的自定义segue是TransitionLegate,试图将其作为一个逻辑单元,因此我无法真正应用保留委托的推理。。。?我的意思是,segue正在运行——因此,代理仍然活着,而且状态良好。我遗漏了一些东西,或者有一个明显的原因,我现在无法理解为什么必须将transitionlegate
与自定义segue分开
我的代码
#定义弹出窗口#u边距25
@接口CardSegue()
@属性(非原子、赋值、getter=isPresenting)布尔呈现;
@结束
@实现卡德塞格
-(无效)履行
{
//确保我们是代表。。。
[self.destinationViewController SetTransitionDelegate:self];
[self.destinationViewController setModalPresentationStyle:UIModalPresentationCustom];
//暴力展示最终结果!
[[self sourceViewController]presentViewController:[self destinationViewController]已设置动画:是完成:无];
}
#pragma mark-UIViewControllerTransitioningDelegate方法
-(id)显示了animationControllerForPresentedController:(UIViewController*)
呈现控制器:(UIViewController*)呈现
sourceController:(UIViewController*)源
{
//配置动画师
自我呈现=是;
回归自我;
}
-(id)animationControllerForDismissedController:(UIViewController*)已解除
{
自我呈现=否;
回归自我;
}
#pragma mark-UIViewControllerContext转换方法
-(NSTimeInterval)transitionDuration:(id)transitionContext
{
返回0.5f;
}
-(void)animateTransfion:(id)transitionContext
{
//从上下文中获取“从”和“到”视图控制器
UIViewController*fromViewController=[transitionContext ViewControllerWorky:UITransitionContextFromViewControllerKey];
UIViewController*toViewController=[transitionContext ViewControllerWorky:UITransitionContextToViewControllerKey];
如果(自我介绍)
{
//设置结束帧。如果有必要,我们将稍后修改此帧
CGRect frame=fromViewController.view.frame;
CGRect endFrame=CGRectMake(弹出框边距,弹出框边距,frame.size.width-2*弹出框边距,frame.size.height-2*弹出框边距);
fromViewController.view.userInteractionEnabled=否;
toViewController.view.alpha=0.0f;
toViewController.view.layer.cornerRadius=15;
//toViewController.view.layer.borderWidth=1.5f;
toViewController.view.layer.masksToBounds=是;
UIView*mainView=[[UIView alloc]initWithFrame:CGRectMake(0,0,frame.size.width,frame.size.height)];
mainView.backgroundColor=[[UIColor alloc]initWithRed:0.0绿色:0.0蓝色:0.0阿尔法:0.0];
[transitionContext.containerView添加子视图:fromViewController.view];
[transitionContext.containerView添加子视图:mainView];
[transitionContext.containerView addSubview:toViewController.view];
CGRect startFrame=结束帧;
startFrame.origin.y-=frame.size.height;
toViewController.view.frame=startFrame;
[UIView animateWithDuration:[self-transitionDuration:transitionContext]动画:^{
mainView.backgroundColor=[[UIColor alloc]initWithRed:0.0绿色:0.0蓝色:0.0阿尔法:0.5];
fromViewController.view.tintAdjustmentMode=UIViewTintAdjustmentMode变暗;
toViewController.view.frame=结束帧;
toViewController.view.alpha=1.0f;
}完成:^(布尔完成){
[transitionContext completeTransition:是];
}];
}
否则{
//设置结束帧。如果有必要,我们将稍后修改此帧
CGRect frame=toViewController.view.frame;
CGRect endFrame=CGRectMake(弹出框边距,弹出框边距,frame.size.width-2*弹出框边距,frame.size.height-2*弹出框边距);
toViewController.view.userInteractionEnabled=是;
UIView*mainView=[[UIView alloc]initWithFrame:CGRectMake(0,0,frame.size.width,frame.size.height)];
mainView.backgroundColor=[[UIColor alloc]initWithRed:0.0绿色:0.0蓝色:0.0阿尔法:0.5];
[transitionContext.containerView addSubview:toViewController.view];
[transitionContext.containerView添加子视图:mainView];
[transitionContext.containerView添加子视图:fromViewController.view];
endFrame.origin.y+=frame.size.height;
[UIView animateWithDuration:[self-transitionDuration:transitionContext]动画:^{
toViewController.view.tintAdjustmentMode=UIViewTintAdjustmentModeAutomatic;
mainView.backgroundColor=[[UIColor alloc]initWithRed:0.0绿色:0.0蓝色:0.0阿尔法:0.0];
UIModalPresentationCustom presentation style can only be used with an animator or with unanimated dismissals.
#define POPUP_MARGIN 25
@interface CardSegue () <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning>
@property (nonatomic, assign, getter = isPresenting) BOOL presenting;
@end
@implementation CardSegue
- (void)perform
{
//Make sure that we are the delegate...
[self.destinationViewController setTransitioningDelegate:self];
[self.destinationViewController setModalPresentationStyle:UIModalPresentationCustom];
//Brute-force show the end-result!
[[self sourceViewController] presentViewController:[self destinationViewController] animated:YES completion:nil];
}
#pragma mark - UIViewControllerTransitioningDelegate Methods
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
//Configure the animator
self.presenting = YES;
return self;
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
self.presenting = NO;
return self;
}
#pragma mark - UIViewControllerContextTransitioning Methods
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.5f;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
// Grab the from and to view controllers from the context
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if (self.presenting)
{
// Set our ending frame. We'll modify this later if we have to
CGRect frame = fromViewController.view.frame;
CGRect endFrame = CGRectMake(POPUP_MARGIN, POPUP_MARGIN, frame.size.width - 2 * POPUP_MARGIN, frame.size.height - 2 * POPUP_MARGIN);
fromViewController.view.userInteractionEnabled = NO;
toViewController.view.alpha = 0.0f;
toViewController.view.layer.cornerRadius = 15;
//toViewController.view.layer.borderWidth = 1.5f;
toViewController.view.layer.masksToBounds = YES;
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
mainView.backgroundColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[transitionContext.containerView addSubview:fromViewController.view];
[transitionContext.containerView addSubview:mainView];
[transitionContext.containerView addSubview:toViewController.view];
CGRect startFrame = endFrame;
startFrame.origin.y -= frame.size.height;
toViewController.view.frame = startFrame;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
mainView.backgroundColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
toViewController.view.frame = endFrame;
toViewController.view.alpha = 1.0f;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
else {
// Set our ending frame. We'll modify this later if we have to
CGRect frame = toViewController.view.frame;
CGRect endFrame = CGRectMake(POPUP_MARGIN, POPUP_MARGIN, frame.size.width - 2 * POPUP_MARGIN, frame.size.height - 2 * POPUP_MARGIN);
toViewController.view.userInteractionEnabled = YES;
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
mainView.backgroundColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
[transitionContext.containerView addSubview:toViewController.view];
[transitionContext.containerView addSubview:mainView];
[transitionContext.containerView addSubview:fromViewController.view];
endFrame.origin.y += frame.size.height;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
mainView.backgroundColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
fromViewController.view.frame = endFrame;
fromViewController.view.alpha = 0.0f;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
}
@end