iOS开发——动画篇Swift篇&炫酷弹出菜单

时间:2023-01-12 13:25:01

炫酷弹出菜单

 
这个是一个第三方按钮菜单组件,原版是使用Objective-C编写的名为AwesomeMenu的组件,地址是:https://github.com/levey/AwesomeMenu
这里改造成了Swift版,效果图如下:
 iOS开发——动画篇Swift篇&炫酷弹出菜单
  iOS开发——动画篇Swift篇&炫酷弹出菜单
  iOS开发——动画篇Swift篇&炫酷弹出菜单
 
使用代码:
 import UIKit

 class ViewController: UIViewController,HanggeSwiftMenuDelegate {

     override func viewDidLoad() {
         super.viewDidLoad()
         // Do any additional setup after loading the view, typically from a nib.

         var storyMenuItemImage =  UIImage(named:"bg-menuitem.png")
         var storyMenuItemImagePressed =  UIImage(named:"bg-menuitem-highlighted.png")
         var starImage =  UIImage(named:"icon-star.png")

         // Default Menu
         var starMenuItem1 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem2 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem3 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem4 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem5 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem6 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem7 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem8 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)
         var starMenuItem9 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
             highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
             highlightedContentImage:nil)

         var menus =  [starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4,
             starMenuItem5, starMenuItem6, starMenuItem7,starMenuItem8,starMenuItem9]

         var startItem =  HanggeSwiftMenuItem(image:UIImage(named:"bg-addbutton.png")!,
             highlightedImage:UIImage(named:"bg-addbutton-highlighted.png")!,
             contentImage:UIImage(named:"icon-plus.png")!,
             highlightedContentImage:UIImage(named:"icon-plus-highlighted.png")
         )

         var menu =  HanggeSwiftMenu(frame:self.view.bounds, startItem:startItem, aMenusArray:menus)
         menu.delegate = self
         self.view.addSubview(menu)

     }

     func SwiftSelectMenu(menu:HanggeSwiftMenu, didSelectIndex idx:Int)
     {

         println("Select the index : %d",idx)
     }

     func HanggeSwiftMenuDidFinishAnimationClose(menu:HanggeSwiftMenu)
     {

         println("Menu was closed!")
     }

     func HanggeSwiftMenuDidFinishAnimationOpen(menu:HanggeSwiftMenu)
     {

         println("Menu is open!")
     }

     func HanggeSwiftMenuWillAnimateOpen(menu:HanggeSwiftMenu)
     {

     }

     func HanggeSwiftMenuWillAnimateClose(menu:HanggeSwiftMenu)
     {

     }

     override func didReceiveMemoryWarning() {
         super.didReceiveMemoryWarning()
         // Dispose of any resources that can be recreated.
     }
 }

还有一个框架也是笔者非常喜欢的,在github上也是备受青睐:https://github.com/nicklockwood/iCarousel

不过目前swift版的还没有发布,如果你真想你的App更加生动,但是自己又不太想写,那么这个非常适合你