GithubHelp home page GithubHelp logo

rnystrom / rnfrostedsidebar Goto Github PK

View Code? Open in Web Editor NEW
2.1K 106.0 340.0 2.81 MB

A Control Center-esque control with blurred background and toggle animations.

License: MIT License

Objective-C 98.23% Ruby 1.77%

rnfrostedsidebar's Introduction

RNFrostedSidebar

Add your own Control Center-esque UI to your app to work as navigation or even toggle different settings. Blend right into the new iOS 7 design with animated blurs, flat design, and custom animations.

This project is another UI control built after finding some inspiration on Dribbble. The original design was created by Jakub Antalik.

For some thoughts on live blur in iOS apps, check out my blog post.

You'll notice that this control's use of blur does not match Jakub's original design exactly. In the original design the background of the buttons is blurred, while the overlay of the control is simply shaded. There have been attempts at recreating this effect, but it is rumored that live-blurring takes place at a much lower level on the GPU and there would be security concerns were we to have access.

Apple is being a little deceptive with their use of blurring in iOS 7. Bottom line, don't animate blurs in your designs.

If you examine the source of this project you'll see that I'm actually cheating to get the blur layer to animate overtop the original view.

Installation

The preferred method of installation is with CocoaPods. Just add this line to your Podfile.

pod 'RNFrostedSidebar', '~> 0.2.0'

Or if you want to install manually, drag and drop the RNFrostedSidebar .h and .m files into your project. To get this working, you'll need to include the following frameworks in Link Binary with Libraries:

  • QuartzCore
  • Accelerate

Usage

The simplest usage is to create a list of images, initialize a RNFrostedSidebar object, then call the -show method.

NSArray *images = @[
                    [UIImage imageNamed:@"gear"],
                    [UIImage imageNamed:@"globe"],
                    [UIImage imageNamed:@"profile"],
                    [UIImage imageNamed:@"star"]
                    ];

RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:images];
callout.delegate = self;
[callout show];

If you use RNFrostedSidebar with a UINavigationController, you can push another UIViewController after selecting a button. Simply initialize it in sidebar:didTapItemAtIndex:, then push it onto the navigation stack after dimissing the sidebar with -dismissAnimated:completion:.

- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
    if (index == 1) {
        [sidebar dismissAnimated:YES completion:^(BOOL finished) {
            if (finished) {
                UIViewController *secondVC = [[UIViewController alloc] init];
                [self.navigationController pushViewController:secondVC animated:YES];
            }
        }];
    }
}

Customization

I've exposed a healthy amount of options for you to customize the appearance and animation of the control.

- (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices;

Use the parameter selectedIndices to add pre-selected options. Without using the init method below there wont be any visualization of selection. But, you will get the proper enabled/disabled BOOL in the delegate -sidebar:didEnable:itemAtIndex: method.

- (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors;

Use the parameter borderColors to add border effect animations when selecting and deselecting a view.

@property (nonatomic, assign) CGFloat width;

The width of the blurred region. Default 150.

@property (nonatomic, assign) BOOL showFromRight;

Toggle showing the control from the right side of the device. Default NO.

@property (nonatomic, assign) CGFloat animationDuration;

The duration of the show and dismiss animations. Default 0.25.

@property (nonatomic, assign) CGSize itemSize;

The size of the item views. Default is width: 75, height: 75.

@property (nonatomic, strong) UIColor *tintColor;

The tint color of the blur. This can be a tricky property to set. I recommend using the provided alpha. Avoid using solid colors with an alpha of 1. Default white: 0.2, alpha: 0.73.

@property (nonatomic, strong) UIColor *itemBackgroundColor;

The background color for item views. Note: This property must be set with either colorWithWhite:alpha or colorWithRed:green:blue:alpha or it will crash. This is for highlight effects on tapping so the control can derive a darker background when highlighted. Default white: 1, alpha 0.25.

@property (nonatomic, assign) NSUInteger borderWidth;

The border width for item views. Default 2.

@property (nonatomic, weak) id <RNFrostedSidebarDelegate> delegate;

An optional delegate to respond to selection of item views. Optional delegate methods, provided by George Villasboas, include:

- (void)sidebar:(RNFrostedSidebar *)sidebar willShowOnScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didShowOnScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar willDismissFromScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didDismissFromScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index;
- (void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index;

Credits

UI Control structure and View Controller containment practices adopted from Matthias Tretter.

Sample icons provided by Pixeden.

The blur algorithm comes from WWDC 2013's session 208, "What's New in iOS User Interface Design".

Apps

If you've used this project in a live app, please let me know! Nothing makes me happier than seeing someone else take my work and go wild with it.

Contact

License

See LICENSE.

rnfrostedsidebar's People

Contributors

kvting avatar mikejaoudi avatar rnystrom avatar sm11963 avatar stevenpsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rnfrostedsidebar's Issues

Notification Badge On Sidebar

Is there any way to add notification badge on sidebar?
I tried to access the subviews of sidebar content view, as it is the private class 'RNCalloutItemView' I couldn't succeed.

Modifying circular effect

I would like to have the white circle the same size of images because i want color animation the same size of images and not bigger. I've tried my best but have not good results. Where is this size written?

Or how can i apply the effect directly to the images?
Sorry for my english!
Thanks.

Changing views when using storyboards

How would i use the function to change views created with storyboard?

  • (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
    NSLog(@"Tapped item at index %i",index);
    if (index == 1) {
    //code to change view
    [sidebar dismiss];
    }
    }

Customize the spacing of the images in sidebar

How can I customize the spacing of the images in sidebar? I use your control in my project, it's awesome. But I just got four images in sidebar, then I found that there were a space at the bottom of the sidebar.

IOS 7 SideBar

when I was using IOS 6.1.3 the RNFrostedsidebar is still working but when i upgraded to IOS 7 the RNFrostedSidebar doesn't work anymore what should i do to make the RNFrostedSidebar work again?

To remove circular effect

How can I remove the white circle that is been added to each of the item. I changed the tint colour but still there is gap between two item because the circle is still being created.

thank you.

Embedded view doesn't resize on screen rotate when sidebar is used with NavigationController

I have set up a minimum test case of a iOS7 single view storyboard application where the view controller contains a single button that opens an instance of the sidebar as follows:

- (IBAction)menuButtonAction:(id)sender {
    NSArray *images = @[[UIImage imageNamed:@"gear"]];

    RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:images];
    [callout show];
}

If I run the application and rotate the phone everything resizes correctly. However, if I then embed the view in a navigation controller and restart the application, the embedded view no longer resizes when I rotate the screen (as shown below).

sidebarrotate

I've tried replacing [callout show] with [callout showInViewController:self animated:YES]. This solves the resizing issue but causes the sidebar to appear behind the navigation bar which isn't desirable.

I am going to continue investigating, but I thought I'd post this first in case someone else has already experienced this problem.

Add text labels under each Item in the Sidebar.

I want to use the sidebar as the navigation menu in my application. I am trying to make the icons as descriptive as possible, but it's always better to have Text Labels for each of them.

Item label

Could you, please, add item label? Would be nice to have text under the "circle".

blurView leak

The view hierarchy usually looks like this:

normal

But show and dismiss the same instance a couple times:

bad

More than five.

If there are more than five items, the tab bar concept breaks down. I have embedded my controllers in UINavigation and after five tabs, it won't show the Navbar etc., I think because it is doing "more" or something first?

Inconsistent behavior

First, this control is great. Thanks for publishing and supporting it.

The behavior is that either the sidebar does not appear completely or it appears behind the VC but mixes transparency underneath the status bar only. If the current VC is the initial VC, everything works fine. Then after the current VC is dismissed, N (== # button presses) sidebars appear on top of the VC/s underneath.

Until proven otherwise, I assume I'm doing something wrong (PEBKAC).

Update: I'll run this app through Reveal to see if that helps.

Current VC:

- (NSArray *)settingsImagesFilenames {
    return @[@"first", @"second"];
}

- (NSArray *)settingsImages {  // TODO: memoize
    NSMutableArray *result = @[].mutableCopy;
    for (NSString *filename in self.settingsImagesFilenames) {
        [result addObject:[UIImage imageNamed:filename]];
    }
    return result;
}

// wired to a settings button touch up inside
- (IBAction)settingsButtonPressed:(id)sender {
    NSLog(@"RNFrostedSidebar: settings button pressed");
    RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:self.settingsImages];
    callout.delegate = self;
    [callout show];
}

- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
    NSLog(@"RNFrostedSidebar: didTapItemAtIndex tapped: %d", index);
    [sidebar dismissAnimated:YES];
}

Adding Text Instead of Images

Basically, I needed to add Text Instead of Images to RNFrostedSidebar. I was curious to see if you'd want me to make a pull request to add this feature to RNFrostedSidebar. I had to pull out the implementation of RNCalloutItemView into a separate file in order to make an abstract class & which the process by which u add images & that by which u add text inherit from. This was to reduce me repeating code.

Let me know if you'd like me to do this.

Crash during the first run of the demo

After touching the left button of the demo app on my iPad (iOS 6.1.3, Xcode Version 5.0 (5A11365x)), i have a crash with the following message :

2013-09-04 21:52:04.405 RNFrostedSidebar[19315:907] +[UIView animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:]: unrecognized selector sent to class 0x3ccb6a18
2013-09-04 21:52:04.410 RNFrostedSidebar[19315:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIView animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:]: unrecognized selector sent to class 0x3ccb6a18'
*** First throw call stack:
(0x344022a3 0x3c29897f 0x34405ca3 0x34404531 0x3435bf68 0xff82d 0x343f69a1 0x34358b6b 0xff361 0xffbb9 0xffbf5 0x103573 0x362f50c5 0x362f5077 0x362f5055 0x362f490b 0x362f4e01 0x3621d5f1 0x3620a801 0x3620a11b 0x37efe5a3 0x37efe1d3 0x343d7173 0x343d7117 0x343d5f99 0x34348ebd 0x34348d49 0x37efd2eb 0x3625e301 0xfb7e5 0x3c6cfb20)
libc++abi.dylib: terminate called throwing an exception

Hidden Circular Shape

How can I delete circular shape in the images of sidebar? I use your control in my project, it's awesome. But I need hide the circular shape.

Thanks in advance!

unrecognized selector sent to instance 0x7f96bb8eede0

With the follow code:

let leftItemIcons = ["musicBarItem", "lightBarItem", "bleBarItem", "settingBarItem"]
var leftItemColors = [UIColor.black25PercentColor(), UIColor.black25PercentColor(), UIColor.black25PercentColor(), UIColor.black25PercentColor()];

var leftBar = RNFrostedSidebar(images: leftItemIcons, selectedIndices: NSIndexSet(index: 1), borderColors: leftItemColors);
leftBar.delegate = self;
leftBar.show();

It failed at the line view.imageView.image = image; in [_images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop)

Popping back to a ViewController containing sidebar does not work properly

When attempting to pop from a view controller back to a view controller containing this sidebar, you end up on a blank view, not where you logically want to be.

For example, the sidebar contains a logout button, which when pressed pushes the LoginViewController onto the stack. When a user logs in, the LoginViewController is popped off the stack but you do not end up back where you started, you end up on a completely blank view.

I am using these methods:

  • (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
    [sidebar dismissAnimated:YES completion:^(BOOL finished) {
    if (finished) {
    // Push to login if index = 2....
    }
    }];
    }

I suspect this is because of how the sidebar is being presented, but if anyone knows how to get around this I would appreciate the help.

Please update pod spec to the latest version

It looks like there are changes that haven't been tagged yet but are in master and in your read me like the dismissAnimated with a completion block. Can you please update the pod?

iOS 7 error

in iOS 7 it showing an error method "animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:" not found..
Please help me to solve this

Slow Performance on iOS7 on iPad 3

I tried the example app on iOS 7 / iPad 3 and the performance was slow. It took closed to 2 seconds for menu to pop out.

When I tried the sample app on iOS 7 / iPhone 4, performance was very fast.

Those are the only devices I have so I don't know the performance on, say, iPad 4.

RNFrostedSidebar compiled as "Objective-C++” problem

I have a project that has to be set to "Objective-C++" for the "compile source as" value (no, "according to file type" will not work in my main project). I am having compile errors when using your RNFrostedSidebar compiled as "Objective-C++”.
Can anyone help me solving it?

problem Soved
It turns out that I forgot to link some libraries
Accelerate.framework
QuartzCore.framework

No animation when selecting an image from the sidebar

68747470733a2f2f7261772e6769746875622e636f6d2f726e797374726f6d2f524e46726f737465644d656e752f6d61737465722f696d616765732f636c69636b2e676966

I followed your steps:

-(RNFrostedSidebar *) sideBar {
  if (!_sideBar) {
    _indexSet = [NSMutableIndexSet indexSetWithIndex:1];
    _images = @[[UIImage imageNamed:@"fixing_tools"],
                [UIImage imageNamed:@"red_cross"],
                [UIImage imageNamed:@"settings"],
                ];
    _colors = @[[UIColor greenColor],
                [UIColor whiteColor],
                [UIColor yellowColor]
                ];
    _sideBar = [[RNFrostedSidebar alloc] initWithImages:_images selectedIndices:self.indexSet borderColors:_colors];
    _sideBar.delegate = self;
  }
  return _sideBar;
}
-(void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
  [[[WFAppDelegate sharedDelegate] window] setRootViewController:[self.controllers objectAtIndex:index]];
}

-(void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index  {

  if (itemEnabled) {
    [self.indexSet addIndex:index];
  }
  else {
    [self.indexSet removeIndex:index];
  }
}

But nothing happens.

Handle rotation of orientation on iOS 7+

Use-case A

rotation

  1. Start from portrait.
  2. Present the sidebar.
  3. Rotate to landscape.
  4. Hmm, something doesn't look quite right.

Use-case B

rotation

  1. Start from landscape.
  2. Present the sidebar.
  3. Rotate to portrait.
  4. Hmm, something doesn't look quite right either.

Implementation

Hello,
Thanks for this great library! I am using this with a navigation controller. Do I need to repeat the images and color in every controller? Sorry if this is a basic question, I am a newbie. I am wondering if there is a more efficient way of doing this.

Thanks!

Change size of View.

Good morning. I would like to know how I can change the size of the view, as I have this problem. I am using Xcode 5, and running IOS 7.
img_3224

Thank you.

Option for allowing only one enabled item at a time

Id like to use this as a menu where I would only allow for one item to be enabled (highlighted) at a time. Does not seem to be anyway to iterate through items to enable/disable them and no flag to disable all items when one is selected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.