How to make an slide animation while bringing an custom view in Cocoa?

前端 未结 4 1858
礼貌的吻别
礼貌的吻别 2020-12-13 08:16

I\'m developing an app where when clicking to a button, custom view should slide from a side. Actually just a window appears, but I\'d like to have something like iOS naviga

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 08:38

    NSView *view = yourview;
    view.wantsLayer = YES;
    

    // Set the layer redraw policy. This would be better done in the initialization method of a NSView subclass instead of here.

     view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay; 
    

    Then,

     [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context)
                        {
                            context.duration = 2.f;
                            view.animator.frame = CGRectOffset(view.frame, 180, 0);
                        }
                        completionHandler:^{
                            view.hidden = YES;
    
    
                        }];
    

提交回复
热议问题