0

pic

I want to implement functionality which is shown in above figure. The side menu(blue panel) should open from left hand side when button pressed that I managed but my problem is I have to create this side menu in such a way that it can be reused on other views

But I can't understand how should I implement it so that it can be reused on other views?

If anyone have idea please share it?

Charan
  • 4,940
  • 3
  • 26
  • 43
Curious_k.shree
  • 990
  • 2
  • 18
  • 37
  • You can create one main viewcontroller say parentViewController and then add other view controllers as child of parentViewController.Your black view controller frame will change when you open and close your parent view controller. – Nuzhat Zari Oct 04 '12 at 06:12
  • Add the view on your window.... :) – IronManGill Oct 04 '12 at 06:13
  • make view with side pannel...and add other view on right side on button click – Rajneesh071 Oct 04 '12 at 06:19

4 Answers4

5

If you want to have your own transition like this for all UIViewControllers you could create a category to UIViewController.

This is how you could do the interface:

*.h file:

#import <UIKit/UIKit.h>

@interface UIViewController(Transitions)

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

@end

*.m file

#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

and this is a sample call:

[self presentViewController: myVC withPushDirection:@"fromRight"]; 
user387184
  • 10,953
  • 12
  • 77
  • 147
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

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52
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...

Apple_iOS0304
  • 1,092
  • 1
  • 9
  • 19
0

hey first see this type of logic which i implement in my project..

here give the bool value for open and close the view if required

-(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];
}

i use this login in iPad application so give this type of frame you can give the frame for iPhone :)

and also see this bellow link in which you can see one demo which same like your requirement..

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

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70