0

图片

我想实现如上图所示的功能。当按下我管理的按钮时,侧面菜单(蓝色面板)应该从左侧打开,但我的问题是我必须创建这个侧面菜单,以便它可以在其他视图上重复使用

但是我不明白我应该如何实现它以便可以在其他视图上重用它?

如果有人有想法请分享?

4

4 回答 4

5

如果你想为所有 UIViewControllers 拥有自己的转换,你可以为 UIViewController 创建一个类别。

这是你可以做的界面:

*.h 文件:

#import <UIKit/UIKit.h>

@interface UIViewController(Transitions)

- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction;
- (void) dismissViewControllerWithPushDirection:(NSString *) direction;

@end

*.m 文件

#import "UIViewControllerWithTransitions.h"
#import <QuartzCore/QuartzCore.h>

@implementation UIViewController(Transitions)

- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction {

    [CATransaction begin];

    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;

    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];

    [self presentViewController:viewController animated:NO completion:NULL];

    [CATransaction commit];

}

- (void) dismissViewControllerWithPushDirection:(NSString *) direction {

    [CATransaction begin];

    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;

    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];

    [self dismissViewControllerAnimated:NO completion:NULL];

    [CATransaction commit];

}

@end

这是一个示例调用:

[self presentViewController: myVC withPushDirection:@"fromRight"]; 
于 2012-10-04T06:30:51.490 回答
0

You can add the View to your window... See the link below for further details :)

Programmatically creating Views in IOS (how does it work)?

iOS - adding/removing a subview programmatically

于 2012-10-04T06:16:17.907 回答
0

Use something like this:

[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{["Set your view's new frame here"];} completion:nil];

or you can set the frame of your view to some default location outside the visible area and then in the animation block set your frame where you want it to be finally after sliding out.

[UIView beginAnimation];
//Your new frame here
[UIView commitAnimation];

something like this.. google it accordingly...

于 2012-10-04T06:16:33.053 回答
0

嘿首先看到我在我的项目中实现的这种类型的逻辑..

如果需要,这里给出打开和关闭视图的布尔值

-(IBAction)yourButtonOpen_Clicked:(id)sender
    {

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:viewObjectSlider cache:YES];
        viewObjectSlider.frame=CGRectMake(828, 0, 196, 694);// set your frame here
        [UIView commitAnimations];
    }
-(IBAction)yourButtonClosed_Click:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:viewObjectSlider cache:YES];
    viewObjectSlider.frame=CGRectMake(984, 0, 196, 694);//set yourFrame
    [UIView commitAnimations];
}

我在 iPad 应用程序中使用此登录名,所以给这种类型的框架,你可以给 iPhone 框架:)

还可以查看下面的链接,您可以在其中看到一个与您的要求相同的演示。

http://www.highwaystech.com/index.php/source-code/ios/360-iiviewdeckcontroller-for-ios.html

于 2012-10-04T06:17:24.173 回答