Giter Site home page Giter Site logo

regexident / dlwidgetmenu Goto Github PK

View Code? Open in Web Editor NEW
410.0 21.0 46.0 2.42 MB

Versatile solution for displaying widget menus. Easily adjustable with custom layouts and/or animations.

License: Other

Ruby 2.47% Objective-C 97.53%
menu objective-c

dlwidgetmenu's People

Contributors

jmkk avatar regexident avatar rvi avatar schaechtele 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

dlwidgetmenu's Issues

Hard to use

Hi, I have just tried to implement this and I could really do with some implementation instructions.

Whats the simplest way to add this to a view? I've looked at the demo but can't get it to work. I've added these from your demo.

In viewdidLoad:

CGRect frame = self.view.bounds;
    id<DLWMMenuLayout> layout = [[DLWMRadialLayout alloc] initWithRadius:60.0 arc:DLWMFullCircle angle:0.0 minDistance:0.0];;
    DLWMMenu *menu = [[DLWMMenu alloc] initWithMainItemView:self.view
                                                 dataSource:self
                                                 itemSource:self
                                                   delegate:self
                                               itemDelegate:self
                                                     layout:layout
                                          representedObject:self];
    menu.openAnimationDelayBetweenItems = 0.01;
    menu.closeAnimationDelayBetweenItems = 0.01;

    menu.center = CGPointMake(CGRectGetMidX(frame), CGRectGetMaxY(frame) * 0.66);
    self.menu = menu;

    [self.view insertSubview:menu atIndex:0];

Then I add:

#pragma mark - DLWMMenuDataSource Protocol

- (NSUInteger)numberOfObjectsInMenu:(DLWMMenu *)menu {
    return 5;
}

- (id)objectAtIndex:(NSUInteger)index inMenu:(DLWMMenu *)menu {
    return @(index);
}

#pragma mark - DLWMMenuItemSource Protocol

+ (UIView *)menuItemView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)];
    view.layer.borderColor = [UIColor colorWithWhite:1.0 alpha:0.75].CGColor;
    view.layer.borderWidth = 1.5;
    view.layer.shadowColor = [UIColor blackColor].CGColor;
    view.layer.shadowOffset = CGSizeMake(0.0, 1.5);
    view.layer.shadowOpacity = 0.5;

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = view.layer.bounds;
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithWhite:1.0 alpha:0.5].CGColor,
                             (__bridge id)[UIColor colorWithWhite:1.0 alpha:0.1].CGColor,
                             (__bridge id)[UIColor colorWithWhite:1.0 alpha:0.0].CGColor,
                             (__bridge id)[UIColor colorWithWhite:1.0 alpha:0.2].CGColor];
    gradientLayer.locations = @[@0.0, @0.49, @0.5, @1.0];
    [view.layer addSublayer:gradientLayer];
    return view;
}

- (UIView *)viewForMainItemInMenu:(DLWMMenu *)menu {
    UIView *view = [[self class] menuItemView];
    view.bounds = CGRectMake(0.0, 0.0, 50.0, 50.0);
    view.backgroundColor = [UIColor lightGrayColor];
    view.layer.cornerRadius = 25.0;
    CAGradientLayer *gradientLayer = (CAGradientLayer *)view.layer.sublayers[0];
    gradientLayer.cornerRadius = view.layer.cornerRadius;
    gradientLayer.frame = view.layer.bounds;
    return view;
}

- (UIView *)viewForObject:(id)object atIndex:(NSUInteger)index inMenu:(DLWMMenu *)menu {
    UIView *view = [[self class] menuItemView];
    view.bounds = CGRectMake(0.0, 0.0, 40.0, 40.0);
    CGFloat hue = ((1.0 / [self numberOfObjectsInMenu:menu]) * index);
    view.backgroundColor = [UIColor colorWithHue:hue saturation:1.0 brightness:1.0 alpha:1.0];
    view.layer.cornerRadius = 20.0;
    CAGradientLayer *gradientLayer = (CAGradientLayer *)view.layer.sublayers[0];
    gradientLayer.cornerRadius = view.layer.cornerRadius;
    gradientLayer.frame = view.layer.bounds;
    return view;
}

When I run it, it runs really slow then eventually stops on the insertSubview line, even when I have global breakpoints switched off.

Menu bounces to centre of frame when a gesture is received while the menu is opening

Hello.

I'm trying to implement a radial menu where you could tap and hold the menu, which will open the menu and close it when the finger is lifted. The implementation works almost entirely, other than if you
lift your finger, while the menu is still opening, and immediately tap and hold the menu (and drag) it again. This results in the menu (or the mainItem of the menu) to bounce to the centre of the frame.

The following is my implementation. [self checkHitTarget] simply checks which item DLWMMenuItem is selected.

- (void)receivedPan:(UIPanGestureRecognizer *)recognizer onItem:(DLWMMenuItem *)item inMenu:(DLWMMenu *)menu {

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            if ([menu isClosedOrClosing]) {
                [self.menu open];
            }
            break;
        case UIGestureRecognizerStateChanged:
            [self checkHitTarget];
        case UIGestureRecognizerStateEnded:
        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateFailed:
            if ([menu isOpenedOrOpening]){
                if (item == menu.mainItem){
                    [self.menu close];
                } else {
                    [menu closeWithSpecialAnimator:[[DLWMSelectionMenuAnimator alloc]init] forItem:item];
                }
            }
            break;
        default:
            break;
    }
}

I've tried going through most of the DLWMMenu implementation dropping break points everywhere, but I still can't pinpoint the exact place it'll break. I'm guessing it's something to do with the state of the menu while the menu is animating (closing or opening)

The Long Press Recognizer fires twice

The state is not examined in the recognizer so it fires on begin and end. I am using it as a toggle without closing the menu. My workaround code for now is to just fire on StateBegan:

 - (void)receivedLongPress:(UILongPressGestureRecognizer *)recognizer {
    if (!self.enabled) {
        return;
    }
     if ([recognizer state] == UIGestureRecognizerStateBegan){
        if ([self.delegate respondsToSelector:@selector(receivedLongPress:onItem:inMenu:)]) {
            [self.delegate receivedLongPress:recognizer onItem:(DLWMMenuItem *)recognizer.view inMenu:self];
        }
     }
 }

Suggestion: demo code could store menu item index in view tag

I am struggling to animate a long press touch from the delegate. The Animators require an index that is not readily available in the delegate for the long press. In your demo code you could show hiding it in a view Tag. I am using the represented object for my own data lookup.

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.