objective-c - 从 super View 中删除并启用用户交互

标签 objective-c ios cocoa-touch uiviewanimation

我正在做一些自定义动画以通过一种方法更改 View 。我已经使用 [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)] 从 superView 中删除了“fromView” ,但我也想在动画结束后启用用户交互。
这是我的代码:

-(void) switchFrom:(UIViewController*) fromViewController To:(UIViewController*) toViewController usingAnimation:(int) animation{
    UIView *fromView = fromViewController.view;
    UIView *toView = toViewController.view;
    /*************** SET ALL DEFAULT TRANSITION SETTINGS ***************/
    // Get the current view frame, width and height
    CGRect pageFrame = fromView.frame;
    CGFloat pageWidth = pageFrame.size.width;
    
    // Create the animation
    [UIView beginAnimations:nil context:nil];
    
    // Create the delegate, so the "fromView" is removed after the transition
    [UIView setAnimationDelegate: fromView];
    [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
    
    // Set the transition duration
    [UIView setAnimationDuration: 0.4];

    /*************** IT DOESN'T WORK AT ALL ***************/
    [toView setUserInteractionEnabled:NO];
    [UIView setAnimationDelegate: toView];
    [UIView setAnimationDidStopSelector:@selector(setUserInteractionEnabled:)];
    [toView setUserInteractionEnabled:YES];

    // Add the "toView" as subview of "fromView" superview
    [fromView.superview addSubview:toView];
    switch (animation) {
        case AnimationPushFromRigh:{
            // Position the "toView" to the right corner of the page            
            toView.frame = CGRectOffset(pageFrame, pageWidth,0);
            
            // Animate the "fromView" to the left corner of the page
            fromView.frame = CGRectOffset(pageFrame, -pageWidth,0);
            
            // Animate the "toView" to the center of the page
            toView.frame = pageFrame;
            
            // Animate the "fromView" alpha
            fromView.alpha = 0;
            
            // Set and animate the "toView" alpha
            toView.alpha = 0;
            toView.alpha = 1;

            // Commit the animation
            [UIView commitAnimations];
        }
        .
        .
        .
知道如何在 setAnimationDidStopSelector 中调用这两种方法并真正让他们一起工作?
编辑 1
尝试了这样的 @safecase 代码,替换了这个注释 block :
/*************** IT DOESN'T WORK AT ALL ***************
[toView setUserInteractionEnabled:NO];
[UIView setAnimationDelegate: toView];
[UIView setAnimationDidStopSelector:@selector(setUserInteractionEnabled:)];
[toView setUserInteractionEnabled:YES];
*************** IT DOESN'T WORK AT ALL ***************/
// Remove the interaction
[toView setUserInteractionEnabled:NO];
[fromView setUserInteractionEnabled:NO];
// Create the animation
[UIView animateWithDuration:0.4 animations:^{
    [fromView performSelector:@selector(removeFromSuperview)];
    }
    completion:^(BOOL finished){
        [UIView animateWithDuration:0.4 
        animations:^{ 
            C6Log(@"finished");
            [toView performSelector: @selector(setUserInteractionEnabled:)];
        }];
    }];
删除了“toView”而不是删除了“fromView”:(
按钮在动画期间继续交互

最佳答案

你知道吗beginIgnoringInteractionEventsendIgnoringInteractionEvents ?
通常,如果您在动画期间不想要任何 userInteraction,您会使用它们。

无论如何,您仍然需要正确的回调来触发它们。

关于objective-c - 从 super View 中删除并启用用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10996227/

相关文章:

iOS 视频播放器擦洗图像

ios - 与父(根) View 的宽度/高度相等?

ios - FB 用户 emailID 未获取

objective-c - 如何在午夜获取今天的 NSDate 对象?

objective-c - 后退按钮未出现在推送的 UIViewController 上

iPhone SDK 4 "Half curl page transition"

objective-c - 如何使用 Storyboard设置代表

ios - 如何在 iOS Objective C 中向 Rest Web 服务请求添加 token

objective-c - 使用 iOS 进行 Twitter 身份验证

ios - 如何使用解析缓存策略