当前位置: > > > Swift - 炫酷放射弹出按钮菜单(改造自AwesomeMenu)

Swift - 炫酷放射弹出按钮菜单(改造自AwesomeMenu)

(本文代码已升级至Swift3)

这个是一个第三方按钮菜单组件,原版是使用Objective-C编写的名为AwesomeMenu的组件,地址是:https://github.com/levey/AwesomeMenu

这里改造成了Swift版,效果图如下:
 
  
  

使用代码:
import UIKit

class ViewController: UIViewController,HanggeSwiftMenuDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let storyMenuItemImage =  UIImage(named:"bg-menuitem.png")
        let storyMenuItemImagePressed =  UIImage(named:"bg-menuitem-highlighted.png")
        let starImage =  UIImage(named:"icon-star.png")
        
        // Default Menu
        let starMenuItem1 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem2 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem3 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem4 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem5 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem6 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem7 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem8 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        let starMenuItem9 =  HanggeSwiftMenuItem(image:storyMenuItemImage!,
            highlightedImage:storyMenuItemImagePressed!, contentImage:starImage!,
            highlightedContentImage:nil)
        
        let menus =  [starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4,
            starMenuItem5, starMenuItem6, starMenuItem7,starMenuItem8,starMenuItem9]
        
        let 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")
        )
        
        let menu =  HanggeSwiftMenu(frame:self.view.bounds, startItem:startItem,
                                    aMenusArray:menus)
        menu.delegate = self
        self.view.addSubview(menu)
    }
   
    func SwiftSelectMenu(_ menu:HanggeSwiftMenu, didSelectIndex idx:Int)
    {
        
        print("Select the index : %d",idx)
    }
    
    func HanggeSwiftMenuDidFinishAnimationClose(_ menu:HanggeSwiftMenu)
    {
        
        print("Menu was closed!")
    }
    
    func HanggeSwiftMenuDidFinishAnimationOpen(_ menu:HanggeSwiftMenu)
    {
        
        print("Menu is open!")
    }
    
    func HanggeSwiftMenuWillAnimateOpen(_ menu:HanggeSwiftMenu)
    {
        
    }
    
    func HanggeSwiftMenuWillAnimateClose(_ menu:HanggeSwiftMenu)
    {
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}


源码下载:HanggeMenu.zip
评论3
  • 3楼
    2017-04-12 17:13
    iOS菜鸟

    swift3全是报错

    站长回复

    这个写的比较早,现已更新成Swift3的,你可以再看下。

  • 2楼
    2015-10-19 17:34
    木头人

    源码报错太多实在改不动了

    站长回复

    现已修改,可以重新下载样例。

  • 1楼
    2015-08-23 21:05
    iOS122

    http://www.ios122.com/2015/08/awesomemenu/ 这是我整理的awesomemenu 上的github上的最新版,LZ这个是官方出的swift版吗?我在github上,没有看到相关的 issue 或者 pull request.

    站长回复

    这个不是官方出的,那时官方还没有出Swift版(不知道现在有没有了),这个是当时参照OC版改的。