Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed name of MenuBurst to ExpandableNavigation.

  • Loading branch information...
commit d5f4ef67a95e91717bbd4d14266682423176b31f 1 parent 9bb24f4
@tobins authored
View
12 PathMenuExample.xcodeproj/project.pbxproj
@@ -15,7 +15,7 @@
AB0A2A9514BB6C3E0009E3BE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = AB0A2A9414BB6C3E0009E3BE /* AppDelegate.m */; };
AB0A2A9814BB6C3E0009E3BE /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB0A2A9714BB6C3E0009E3BE /* ViewController.m */; };
AB0A2A9B14BB6C3E0009E3BE /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AB0A2A9914BB6C3E0009E3BE /* ViewController.xib */; };
- AB0A2AC714BB6F4A0009E3BE /* MenuBurst.m in Sources */ = {isa = PBXBuildFile; fileRef = AB0A2AC614BB6F4A0009E3BE /* MenuBurst.m */; };
+ AB0A2AC714BB6F4A0009E3BE /* ExpandableNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = AB0A2AC614BB6F4A0009E3BE /* ExpandableNavigation.m */; };
AB0A2AD614BB6F720009E3BE /* background.png in Resources */ = {isa = PBXBuildFile; fileRef = AB0A2AC814BB6F720009E3BE /* background.png */; };
AB0A2AD714BB6F720009E3BE /* background@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AB0A2AC914BB6F720009E3BE /* background@2x.png */; };
AB0A2AD814BB6F720009E3BE /* comment-button.png in Resources */ = {isa = PBXBuildFile; fileRef = AB0A2ACA14BB6F720009E3BE /* comment-button.png */; };
@@ -47,8 +47,8 @@
AB0A2A9614BB6C3E0009E3BE /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
AB0A2A9714BB6C3E0009E3BE /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
AB0A2A9A14BB6C3E0009E3BE /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
- AB0A2AC514BB6F4A0009E3BE /* MenuBurst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuBurst.h; sourceTree = "<group>"; };
- AB0A2AC614BB6F4A0009E3BE /* MenuBurst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuBurst.m; sourceTree = "<group>"; };
+ AB0A2AC514BB6F4A0009E3BE /* ExpandableNavigation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExpandableNavigation.h; sourceTree = "<group>"; };
+ AB0A2AC614BB6F4A0009E3BE /* ExpandableNavigation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExpandableNavigation.m; sourceTree = "<group>"; };
AB0A2AC814BB6F720009E3BE /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = background.png; sourceTree = "<group>"; };
AB0A2AC914BB6F720009E3BE /* background@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "background@2x.png"; sourceTree = "<group>"; };
AB0A2ACA14BB6F720009E3BE /* comment-button.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "comment-button.png"; sourceTree = "<group>"; };
@@ -112,8 +112,8 @@
isa = PBXGroup;
children = (
AB0A2AA114BB6C7F0009E3BE /* Images */,
- AB0A2AC514BB6F4A0009E3BE /* MenuBurst.h */,
- AB0A2AC614BB6F4A0009E3BE /* MenuBurst.m */,
+ AB0A2AC514BB6F4A0009E3BE /* ExpandableNavigation.h */,
+ AB0A2AC614BB6F4A0009E3BE /* ExpandableNavigation.m */,
AB0A2A9314BB6C3E0009E3BE /* AppDelegate.h */,
AB0A2A9414BB6C3E0009E3BE /* AppDelegate.m */,
AB0A2A9614BB6C3E0009E3BE /* ViewController.h */,
@@ -236,7 +236,7 @@
AB0A2A9114BB6C3E0009E3BE /* main.m in Sources */,
AB0A2A9514BB6C3E0009E3BE /* AppDelegate.m in Sources */,
AB0A2A9814BB6C3E0009E3BE /* ViewController.m in Sources */,
- AB0A2AC714BB6F4A0009E3BE /* MenuBurst.m in Sources */,
+ AB0A2AC714BB6F4A0009E3BE /* ExpandableNavigation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
39 PathMenuExample/ExpandableNavigation.h
@@ -0,0 +1,39 @@
+//
+// ExpandableNavigation.h
+// PathMenuExample
+//
+// Created by Tobin Schwaiger-Hastanan on 1/8/12.
+// Copyright (c) 2012 Tobin Schwaiger-Hastanan. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface ExpandableNavigation : NSObject {
+ UIButton* _mainButton;
+ NSArray* _menuItems;
+ CGFloat _radius;
+ CGFloat speed;
+ CGFloat bounce;
+ CGFloat bounceSpeed;
+ BOOL expanded;
+ BOOL transition;
+}
+
+@property (retain) UIButton* mainButton;
+@property (retain) NSArray* menuItems;
+@property CGFloat radius;
+@property CGFloat speed;
+@property CGFloat bounce;
+@property CGFloat bounceSpeed;
+@property (readonly) BOOL expanded;
+@property (readonly) BOOL transition;
+
+- (id)initWithMenuItems:(NSArray*) menuItems
+ mainButton:(UIButton*) mainButton
+ radius:(CGFloat) radius;
+- (id)init;
+
+- (void) expand;
+- (void) collapse;
+
+@end
View
130 PathMenuExample/ExpandableNavigation.m
@@ -0,0 +1,130 @@
+//
+// ExpandableNavigation.m
+// PathMenuExample
+//
+// Created by Tobin Schwaiger-Hastanan on 1/8/12.
+// Copyright (c) 2012 Tobin Schwaiger-Hastanan. All rights reserved.
+//
+
+#import "ExpandableNavigation.h"
+
+@implementation ExpandableNavigation
+
+@synthesize mainButton = _mainButton;
+@synthesize menuItems = _menuItems;
+@synthesize radius = _radius;
+@synthesize speed;
+@synthesize bounce;
+@synthesize bounceSpeed;
+@synthesize expanded;
+@synthesize transition;
+
+
+- (id)initWithMenuItems:(NSArray*) menuItems mainButton:(UIButton*) mainButton radius:(CGFloat) radius {
+
+ if( self = [super init] ) {
+ self.menuItems = menuItems;
+ self.mainButton = mainButton;
+ self.radius = radius;
+ self.speed = 0.15;
+ self.bounce = 0.225;
+ self.bounceSpeed = 0.1;
+ expanded = NO;
+ transition = NO;
+
+ if( self.mainButton != nil ) {
+ for (UIView* view in self.menuItems) {
+
+ view.center = self.mainButton.center;
+ }
+
+ [self.mainButton addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
+ }
+ }
+
+ return self;
+}
+
+- (id)init {
+ return [self initWithMenuItems:nil mainButton:nil radius:32.0];
+}
+
+- (void) expand {
+ transition = YES;
+
+ [UIView animateWithDuration:self.speed animations:^{
+ self.mainButton.transform = CGAffineTransformMakeRotation( 45.0 * 0.0174532925 );
+ }];
+
+ for (UIView* view in self.menuItems) {
+ int index = [self.menuItems indexOfObject:view];
+ CGFloat indexOverCount = ((CGFloat)index/(self.menuItems.count-1));
+ CGFloat rad =(1.0 - indexOverCount) * 90.0 * 0.0174532925;
+ CGAffineTransform rotation = CGAffineTransformMakeRotation( rad );
+ CGFloat x = (self.radius + (self.bounce * self.radius)) * rotation.a;
+ CGFloat y = (self.radius + (self.bounce * self.radius)) * rotation.c;
+ CGPoint center = CGPointMake( view.center.x + x , view.center.y + y);
+ [UIView animateWithDuration: self.speed
+ delay: (self.speed * indexOverCount)
+ options: UIViewAnimationOptionCurveEaseIn
+ animations:^{
+ view.center = center;
+ }
+ completion:^(BOOL finished){
+ [UIView animateWithDuration:self.bounceSpeed
+ animations:^{
+ CGFloat x = (self.bounce * self.radius) * rotation.a;
+ CGFloat y = (self.bounce * self.radius) * rotation.c;
+ CGPoint center = CGPointMake( view.center.x - x , view.center.y - y);
+ view.center = center;
+ }];
+ if( view == self.menuItems.lastObject ) {
+ expanded = YES;
+ transition = NO;
+ }
+ }];
+ }
+}
+
+- (void) collapse {
+ transition = YES;
+
+ [UIView animateWithDuration:self.speed animations:^{
+ self.mainButton.transform = CGAffineTransformMakeRotation( 0 );
+ }];
+
+ for (UIView* view in self.menuItems) {
+ int index = [self.menuItems indexOfObject:view];
+ CGFloat indexOverCount = ((CGFloat)index/(self.menuItems.count-1));
+ [UIView animateWithDuration:self.speed
+ delay:(1.0 - indexOverCount) * self.speed
+ options: UIViewAnimationOptionCurveEaseIn
+ animations:^{
+ view.center = self.mainButton.center;
+ }
+ completion:^(BOOL finished){
+ if( view == self.menuItems.lastObject ) {
+ expanded = NO;
+ transition = NO;
+ }
+ }];
+ }
+}
+
+- (IBAction)press:(id)sender {
+ if( !self.transition ) {
+ if( !self.expanded ) {
+ [self expand];
+ } else {
+ [self collapse];
+ }
+ }
+}
+
+- (void)dealloc {
+ self.mainButton = nil;
+ self.menuItems = nil;
+ [super dealloc];
+}
+
+@end
View
6 PathMenuExample/ViewController.h
@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
-@class MenuBurst;
+@class ExpandableNavigation;
@interface ViewController : UIViewController {
UIButton* button1;
@@ -17,7 +17,7 @@
UIButton* button4;
UIButton* button5;
UIButton* main;
- MenuBurst* menuBurst;
+ ExpandableNavigation* navigation;
}
@property (nonatomic, retain) IBOutlet UIButton *button1;
@@ -27,7 +27,7 @@
@property (nonatomic, retain) IBOutlet UIButton *button5;
@property (nonatomic, retain) IBOutlet UIButton *main;
-@property (retain) MenuBurst* menuBurst;
+@property (retain) ExpandableNavigation* navigation;
- (IBAction) touchMenuItem:(id)sender;
View
15 PathMenuExample/ViewController.m
@@ -7,7 +7,7 @@
//
#import "ViewController.h"
-#import "MenuBurst.h"
+#import "ExpandableNavigation.h"
@implementation ViewController
@@ -17,7 +17,7 @@ @implementation ViewController
@synthesize button4;
@synthesize button5;
@synthesize main;
-@synthesize menuBurst;
+@synthesize navigation;
- (void)didReceiveMemoryWarning
{
@@ -31,10 +31,10 @@ - (void)viewDidLoad
{
[super viewDidLoad];
- // initialize MenuBurst object with an array of buttons.
+ // initialize ExpandableNavigation object with an array of buttons.
NSArray* buttons = [NSArray arrayWithObjects:button1, button2, button3, button4, button5, nil];
- self.menuBurst = [[[MenuBurst alloc] initWithMenuItems:buttons mainButton:self.main radius:120.0] autorelease];
+ self.navigation = [[[ExpandableNavigation alloc] initWithMenuItems:buttons mainButton:self.main radius:120.0] autorelease];
}
- (void)viewDidUnload
@@ -47,8 +47,7 @@ - (void)viewDidUnload
self.button4 = nil;
self.button5 = nil;
self.main = nil;
- self.menuBurst = nil;
- // e.g. self.myOutlet = nil;
+ self.navigation = nil;
}
- (void)viewWillAppear:(BOOL)animated
@@ -87,8 +86,8 @@ - (IBAction) touchMenuItem:(id)sender {
otherButtonTitles:nil] autorelease];
[message show];
- if( self.menuBurst.expanded ) {
- [self.menuBurst collapse];
+ if( self.navigation.expanded ) {
+ [self.navigation collapse];
}
}
@end
View
4 README
@@ -1,8 +1,8 @@
Overview
========
-Path 2.0's iPhone app has a really neat menu/navigation system. This is a simple example of how to add a similar menu menu system to your iPhone app. Just run the example and click on the nice red button.
+Path 2.0's iPhone app has a really neat navigation system. This is a simple example of how to add a similar menu menu system to your iPhone app. Just run the example and click on the nice red button.
-The main menu code for expanding & collapsing an array of menu items/buttons (views) is in the MenuBurst.m/.h files. Looking at the usage example in ViewController.m should be pretty self explanitory. However if you have any questions feel free to reach out to me on twitter (@tobins).
+The navigation code for expanding & collapsing an array of menu items/buttons (views) is in the ExpandableNavigation.m/.h files. Looking at the usage example in ViewController.m should be pretty self explanitory. However if you have any questions feel free to reach out to me on twitter (@tobins).
n'joy!
Please sign in to comment.
Something went wrong with that request. Please try again.