Amazing animations available with MagicPie!

Related tags

Charts MagicPie
Overview

MagicPie

Powerful pie layer for creating your own pie view. PieLayer provide great animation with simple usage.

The main advantage of that control that there is no worry about displaying of animation. Animation will display correctly even if you will add new elements during execution of another slice deleting animation. That's amazing! And here is no delegates. I like delegates, but in this case I think they are excess.

Demo

Demo

Be creative =)

Demo

Demo

Installation

Edit your PodFile to include the following line:

pod 'MagicPie'

Then import the main header.

#import <MagicPieLayer.h>

Have a fun!

Swift Swift Swift Swift Swift

Okay, now when you are reading this, I recommend to you look the example #2 in Swift.

Example Usage

Create pie:

Obj-C
PieLayer* pieLayer = [[PieLayer alloc] init];
pieLayer.frame = CGRectMake(0, 0, 200, 200);
[self.view.layer addSublayer:pieLayer];
Swift
let pieLayer = PieLayer()
pieLayer.frame = CGRectMake(0, 0, 200, 200)
view.layer.addSublayer(pieLayer)

Add slices:

Obj-C
[pieLayer addValues:@[[PieElement pieElementWithValue:5.0 color:[UIColor redColor]],
                      [PieElement pieElementWithValue:4.0 color:[UIColor blueColor]],
                      [PieElement pieElementWithValue:7.0 color:[UIColor greenColor]]] animated:YES];
Swift
pieLayer.addValues([PieElement(value: 5.0, color: UIColor.redColor()),
                    PieElement(value: 4.0, color: UIColor.blueColor()),
                    PieElement(value: 7.0, color: UIColor.greenColor())], animated: true)

Change value with animation:

Obj-C
PieElement* pieElem = pieLayer.values[0];
[PieElement animateChanges:^{
	pieElem.val = 13.0;
	pieElem.color = [UIColor yellowColor];
}];
Swift
let pieElem = pieLayer.values[0]
PieElement.animateChanges {
	pieElem.val = 13.0
	pieElem.color = UIColor.yellowColor()
}

Delete slices:

Obj-C
[pieLayer deleteValues:@[pieLayer.values[0], pieLayer.values[1]] animated:YES];
Swift
pieLayer.deleteValues([pieLayer.values[0], pieLayer.values[1]], animated: true)

Contact

Alexandr Graschenkov: [email protected]

License

MagicPie is available under the MIT license.

Copyright © 2013 Alexandr Graschenkov.

Comments
  • Problems starting angle of a pie chart

    Problems starting angle of a pie chart

    Hi,

    `PieLayer *pieLayer = [[PieLayer alloc] init]; pieLayer.frame = CGRectMake(100, 100, 200, 200); pieLayer.maxRadius = 60; pieLayer.minRadius = 30; pieLayer.startAngle = 0; pieLayer.endAngle = 360; pieLayer.showTitles = ShowTitlesNever;

    PieElement *elem1 = [PieElement pieElementWithValue:1 color:[self randomColor]];
    PieElement *elem2 = [PieElement pieElementWithValue:3 color:[self randomColor]];
    
    [pieLayer addValues:@[elem1] animated:NO];
    [pieLayer addValues:@[elem2] animated:NO];
    
    [self.view.layer addSublayer:pieLayer];`
    

    This is not a problem!

    qq20151021-0

    But, Starting angle is not starting from pieLayer.startAngle = 0; , PieElement *elem1 = [PieElement pieElementWithValue:3 color:[self randomColor]];

    qq20151021-1

    What should I do? Thanks!

    opened by duxinfeng 3
  • Added indexing ability to pie elements

    Added indexing ability to pie elements

    Recently when we were using this awesome library we found that it'll be more convenient to know what's the exact pie element that is tapped being mapped with the input array index. That is if the the input values are in an array as below, float vals[] = {505.0,505.0,0.0,70.0,0.0}; then when the relative pie element is tapped there's no way to identify which pie element is mapped with the index of the above array elements. It gets worse when the there are identical values in the array as above. for example which 505.0 is the user tapped in the pie chart? is it the element at 0th index or at index 1.

    For that reason I have added another overload init method that will map the array index as well.

    • (instancetype)pieElementWithValue:(float)val indexValue:(NSInteger_)index color:(UIColor_)color;

    Hope this may be convenient to others in their developments.

    opened by maduperera 3
  • pie layer not drawing iOS objective c

    pie layer not drawing iOS objective c

    code in view did load

    #import <MagicPieLayer.h>

    PieLayer* pieLayer = [[PieLayer alloc] init]; pieLayer.frame = CGRectMake(0, 0, 200, 200); [self.view.layer addSublayer:pieLayer]; [pieLayer addValues:@[[PieElement pieElementWithValue:5.0 color:[UIColor redColor]], [PieElement pieElementWithValue:4.0 color:[UIColor blueColor]], [PieElement pieElementWithValue:7.0 color:[UIColor greenColor]]] animated:YES];

    there was pie chart created at times but now totally I am not getting any pie chart.what is the issue here?

    opened by akshay1318a 1
  • Is there swift version for pie chart example 2?

    Is there swift version for pie chart example 2?

    I found that there's swift version only for example 4. How can I have swift version for the whole project? Especially for example 2. Example 2 suits for my project. I don't like bridging. I do code in full swift.

    opened by jeslinjohnson 1
  • Added animatable maxRadius on PieElement

    Added animatable maxRadius on PieElement

    I wanted to animate the max radius of a PieElement, without moving the center. So I added the property "maxRadius" to PieElement.

    Check-out the example 2 to see the effect.

    Cheers !

    opened by wes-nz 1
  • Wrong include in PieElement.h

    Wrong include in PieElement.h

    In PieElement.h you include Foundation.h while UIColor is used, which is part of UIKit.h . This can product problems when using MagicPie with Swift.

    Can you replace

    import <Foundation/Foundation.h>

    with

    import <UIKit/UIKit.h>

    Thanks!

    opened by werner-freytag 1
  • pieElemInPoint doesn't seem to work in Swift.

    pieElemInPoint doesn't seem to work in Swift.

    Hi Alexandr, thanks for your library and its really great. But I can't use the pieElemInPoint method to make one section of the pie to move like in your demo example 2.

    here are my codes (in Swift):

    import UIKit
    
    class BlockViewController: UIViewController {
    
    var pieLayer = PieLayer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "Background"))
    
        pieLayer.frame = CGRectMake(55, 120, 200, 200)
        pieLayer.maxRadius = 80
        pieLayer.minRadius = 20
        pieLayer.animationDuration = 1.5
        self.view.layer.addSublayer(pieLayer)
    
        var valuesToAdd : NSArray = [PieElement(value: 5, color: UIColor.redColor()), PieElement(value: 9, color: UIColor.blueColor())]
    
        pieLayer.addValues(valuesToAdd, animated: true)
    
        if pieLayer.self.respondsToSelector("setContentsScale:") {
            pieLayer.contentsScale = UIScreen.mainScreen().scale
        }
    
        let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
        tap.numberOfTapsRequired = 1
        tap.numberOfTouchesRequired = 1
        self.view.addGestureRecognizer(tap)
    }
    
    func handleTap (tap : UITapGestureRecognizer) {
    
        if tap.state != .Ended {
            return
        }
    
        var pos : CGPoint = tap.locationInView(tap.view)
        var tappedElem : PieElement? = pieLayer.pieElemInPoint(pos)
        if !tappedElem { return }
        if tappedElem?.centrOffset > 0 {
            tappedElem = nil
            println("CALLED3")
            PieElement.animateChanges( {for elem : PieElement in self.pieLayer.values as [PieElement] {
                elem.centrOffset = tappedElem==elem ? 20 : 0
                }
            })
        }
    }
    }
    

    I printed the value of pos, and it really has values. I printed the tappedElem, and it always returns nil. Any idea on fixing this issue? Thanks for anyone's help ;)

    opened by HenryHins 1
  • Building for 64-bit architecture cause warnings about precision loss and format arguments

    Building for 64-bit architecture cause warnings about precision loss and format arguments

    Change project architecture to include 64-bit and build, see warning:

    Implicit conversion loses integer precision: 'long' to 'int'
    Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'
    Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'
    Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'
    Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'
    Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'
    Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'
    Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead
    Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead
    Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead
    Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead
    
    opened by gogopair 1
  • Titles do not display when adding values with animation

    Titles do not display when adding values with animation

    I've found that when I add values by calling -(void)addValues:animated: with YES, my titles do not display.

    I believe the issue is in the following lines:

    - (void)insertValues:(NSArray *)array atIndexes:(NSArray *)indexes animated:(BOOL)animated
    {
        ...
        if(!animated || ![self performDelayedAnimation]){
            for(PieElement* elem in array){
                elem.titleAlpha = 1.0;
            }
            [self removeAnimationForKey:_animationValuesKey];
            self.values = [NSArray arrayWithArray:newValues];
            return;
        }
        ...
    }
    

    It seems to me that the function should be setting elem.titleAlpha = 1.0 outside of the if statement (regardless of whether we're inserting values animated or not). Everything works with the following change:

    
    - (void)insertValues:(NSArray *)array atIndexes:(NSArray *)indexes animated:(BOOL)animated
    {
        ...
        for(PieElement* elem in array){
            elem.titleAlpha = 1.0;
        }
        if(!animated || ![self performDelayedAnimation]){
            [self removeAnimationForKey:_animationValuesKey];
            self.values = [NSArray arrayWithArray:newValues];
            return;
        }
        ...
    }
    
    opened by owen-yang 0
  • Quick fix previous fix

    Quick fix previous fix

    Do not commit at night. Do not commit at night. Do not commit at night. Do not commit at night. Do not commit at night. Do not commit at night. Do not commit at night.

    Check all commits before push. Check all commits before push. Check all commits before push. Check all commits before push. Check all commits before push. Check all commits before push.

    Always write test. Always write test. Always write test. Always write test. Always write test. Always write test. Always write test. Always write test. Always write test.

    opened by AlexandrGraschenkov 0
Owner
Alexandr Graschenkov
iOS and Computer Vision developer
Alexandr Graschenkov
🎈 Curated collection of advanced animations that I have developed using (Swift UI for iOS) and (React Native for iOS/Android). Source code is intended to be reused by myself for future projects.

?? Curated collection of advanced animations that I have developed using (Swift UI for iOS) and (React Native for iOS/Android). Source code is intended to be reused by myself for future projects.

Artem Moshnin 5 Apr 3, 2022
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

Andrea Del Fante 103 Aug 12, 2022
Beers is a simple experimental app implemented using the new amazing SwiftUI.

Beers is a simple experimental app implemented using the new amazing SwiftUI. The app shows a list of beers fetched from Punk API

Chris 27 Dec 20, 2022
Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

Andrea Del Fante 103 Aug 12, 2022
The Amazing Audio Engine is a sophisticated framework for iOS audio applications, built so you don't have to.

Important Notice: The Amazing Audio Engine has been retired. See the announcement here The Amazing Audio Engine The Amazing Audio Engine is a sophisti

null 523 Nov 12, 2022
Clima is an amazing weather app for iOS

ClimaApp Clima App é um iOS App desenvolvido em Swift. Clima é um incrível app que mostra o clima da localidade que você deseja saber, esse app foi fe

Breno Vasconcellos 0 Dec 16, 2021
A simple and attractive AlertView to onboard your users in your amazing world.

AlertOnboarding A simple and attractive AlertView to onboard your users in your amazing world. PRESENTATION This AlertOnboarding was inspired by this

Boisney Philippe 832 Jan 8, 2023
Swift-sidebar-menu-example - Create amazing sidebar menu with animation using swift

 SWIFT SIDEBAR MENU EXAMPLE In this project I create a awesome side bar menu fo

Paolo Prodossimo Lopes 4 Jul 25, 2022
UI framework that allows developers to integrate an amazing selection interface into their applications

UI framework that allows developers to integrate an amazing selection interface into their applications! Each bubble has a set of parameters, which could be configured individually.

AJIJIi 5 Jul 12, 2022
A collection of animations for iOS. Simple, just add water animations.

DCAnimationKit A collection of animations for iOS Simply, just add water! DCAnimationKit is a category on UIView to make animations easy to perform. E

Dalton 797 Sep 23, 2022
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
Spin aims to provide a versatile Feedback Loop implementation working with the three main reactive frameworks available in the Swift community (RxSwift, ReactiveSwift and Combine)

With the introduction of Combine and SwiftUI, we will face some transition periods in our code base. Our applications will use both Combine and a thir

Spinners 119 Dec 29, 2022
Notify users when a new version of your app is available and prompt them to upgrade.

Siren ?? Notify users when a new version of your app is available and prompt them to upgrade. Table of Contents Meta About Features Screenshots Ports

Arthur Ariel Sabintsev 4.1k Dec 27, 2022
Ask permissions on Swift. Available List, Dialog & Native interface. Can check state permission.

SPPermissions About Library for ask permissions. You can check state of permissions, available .authorized, .denied & .notDetermined. Available ready-

Ivan Vorobei 5.1k Dec 30, 2022
This is my first SwiftUI project, as I decided not to release it I made the codebase available here for anyone to take a look at.

Sunshine This is my first SwiftUI project, as I decided not to release it to the App Store. I made the codebase available here for anyone to take a lo

Maxime Heckel 20 Dec 14, 2022
Get notified about available COVID-19 vaccination appointments in Berlin's vaccination centers

VaccinationMonitor If you live in Berlin you might know how difficult it is to find an appointment to get a COVID-19 vaccination. This app notifies yo

Christian Lobach 8 Jan 14, 2022
Work in progress gallery of controls available to Catalyst apps using Optimized for Mac

Catalyst Controls Gallery Very simple work-in-progress demonstration of many common controls available to Mac Catalyst as of macOS 11. Provided moreso

Steven Troughton-Smith 163 Sep 18, 2022