iOSCodeSnippets

Transitions

how to implement the normal "swipe left for settings side bar" ?

reference

simple drop down list

ref

left/right swipe segue

//in view did load//
{
    UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
    rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [rightRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:rightRecognizer];
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [leftRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:leftRecognizer];
    }

    - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
    [self performSegueWithIdentifier:@"forward" sender:self];
}

how to add app walkthrough?

  1. detect whether the user is first time launching app or not Reference
  2. perform segue to walkthrough view if it is first time user Refenrence

how to add side bar to the view

reference

how to implement a dropdown list

example1 example2 example3

how to add iOS default share sheet?


    NSString *text = @"hello world";
            NSURL *url = [NSURL URLWithString:@"http://airbob.github.io/lifeNumber"];
            //UIImage *image = [UIImage imageNamed:@"roadfire-icon-square-200"];

            UIActivityViewController *controller =
            [[UIActivityViewController alloc]
             initWithActivityItems:@[text, url]
             applicationActivities:nil];


            controller.excludedActivityTypes = @[UIActivityTypePrint,
                                                 UIActivityTypeCopyToPasteboard,
                                                 UIActivityTypeAssignToContact,
                                                 UIActivityTypeSaveToCameraRoll,
                                                 UIActivityTypeAddToReadingList,
                                                 UIActivityTypeAirDrop];
            [self presentViewController:controller animated:YES completion:nil];

how to dismiss view controller after certain animation (such as modal view, partial curl)

[self dismissViewControllerAnimated:YES completion:nil];

how to display and dismiss modal view programmingly?

[self presentViewController:modalViewController animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];

when display a modal view programmingly, it displays a balck screen, why?

CBModalViewController* modalViewController = [[CBModalViewController alloc] init];
/*this is inconrect if you use storyboard, use following method
(please note the controller identifier is the storyboard id in storyboard
*/

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                             bundle: nil];

    CBModalViewController * modalViewController = (CBModalViewController*)[mainStoryboard
    instantiateViewControllerWithIdentifier: @"CBModalViewController"];

how to set starting view controller conditionally?

  1. uncheck is initial view in storyboard 2.

    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
     CBFBViewController * startViewController = (CBFBViewController*)[storyboard instantiateViewControllerWithIdentifier: @"CBFBViewController"];
    
     self.window.rootViewController = startViewController;
     [self.window makeKeyAndVisible];
    

    reference

whose view is not in the window hierarchy problem

normally add the present controller in viewdidappear instead of viewdidload

how to implement default iOS7 setting back swipe gesture?

reference

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Disable iOS 7 back gesture
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return YES;
}