Kjuly / KYCircleMenu

An iOS UI control that allows you to build a circular menu by laying out buttons in a circle pattern adjusting from the number of buttons (1~6).
MIT License
786 stars 154 forks source link

How can I create a button for my child view, so I can be able to return for the KYCircleMenu? #5

Closed msleal closed 11 years ago

msleal commented 11 years ago

Hello, my name is Leal and I'm starting to play with the iOS apps. Trying to use this awesome UI Control, I'm in the obligation to mess with some files... ;-) The first case below (1) is working fine (does not have nothing on the new view, but is working. I can click on the option 1, go to the new view, and do have a button to go back to the KYCircleMenu. But when I choose the option 2 (case 2), I can go to the google website, and it works fine. The problem is that I do not have the button to go back to the KYCircleMenu.

Here is the code:

#pragma mark - KYCircleMenu Button Action

// Run button action depend on their tags:
//
// TAG:        1       1   2      1   2     1   2     1 2 3     1 2 3
//            \|/       \|/        \|/       \|/       \|/       \|/
// COUNT: 1) --|--  2) --|--   3) --|--  4) --|--  5) --|--  6) --|--
//            /|\       /|\        /|\       /|\       /|\       /|\
// TAG:                             3       3   4     4   5     4 5 6
//
- (void)runButtonActions:(id)sender {
  [super runButtonActions:sender];
    switch ([sender tag]) {
        case 1: {
            // Do a thing
            // Configure new view & push it with custom |pushViewController:| method
            //NSLog(@"Debug - TAG: %d", [sender tag]);
            UIViewController *viewController = [[UIViewController alloc] init];
            [viewController.view setBackgroundColor:[UIColor blackColor]];
            [viewController setTitle:[NSString stringWithFormat:@"Cadastro"]];
            // Use KYCircleMenu's |-pushViewController:| to push vc
            [self pushViewController:viewController];
            [viewController release];
        }
            break;

        case 2: {
            // Initializing the UIWebView interface...
            UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
            webView.userInteractionEnabled = YES;
            NSString *urlAddress = @"http://www.google.com";
            // NSLog(@"Debug - We should open the URL: %@", urlAddress);
            NSURL *url = [NSURL URLWithString:urlAddress];
            NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
            //[webView.scrollView flashScrollIndicators];
            //Load the request in the UIWebView.
            [webView loadRequest:requestObj];
            [self.view addSubview:webView];
            [webView release];
        }
            break;

        case 3:
            // Just logging for now...
            // NSLog(@"Debug - TAG: %d", [sender tag]);
            break;

        case 4:
            // Just logging for now...
            // NSLog(@"Debug - TAG: %d", [sender tag]);
            break;

        case 5:
            // Just logging for now...
            // NSLog(@"Debug - TAG: %d", [sender tag]);
            break;

        case 6:
            // Just logging for now...
            // NSLog(@"Debug - TAG: %d", [sender tag]);
            break;

        default:
            // We should not be here...
            break;
    }
}

@end
Kjuly commented 11 years ago

If you want to use a button instead of back button (on navigation bar), you need to create a button together with the circle menu, i.e., insert circle menu below the button.

You can take a look at THIS CLASS, I created a centerMainButton_ together with centerMenuUtilityViewController_ (which is a subclass from KYCircleMenu). Then I can use centerMainButton_ to control "back action" for all child views.

In this case, I suggest you to use iPokeMon branch of KYCircleMenu, though it's in development. ;)

Kjuly commented 11 years ago

Here's the DEMO VIDEO, or the NEW ONE.

msleal commented 11 years ago

Hi Kjuly! No, I just want to have the navigation bar (the back button), the same as I have when I select the option 1. I don't know why the back button is on the first option, and not on the second... I think I need to add the navigation bar with the back button, just don't know where I need to add this code.

Kjuly commented 11 years ago

I see, you need to use -pushViewController: instead of -addSubview:. So try to replace

[self.view addSubview:webView];

to

UIViewController *webViewController = [[UIViewController alloc] init];
...
// Here |webViewController| is a wrap for |webView|, so you can push it by |-pushViewController:| method.
[webViewController.view addSubview:webView];
[self pushViewController:webViewController];
...
msleal commented 11 years ago

Perfect... Thank you very much!

Kjuly commented 11 years ago

My pleasure :)