Convert Figma logo to code with AI

Yalantis logoPersei

Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift

3,453
317
3,453
2

Top Related Projects

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

5,370

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.

This component implements transition animation to crumble view-controller into tiny pieces.

Animated side menu with customizable UI

Quick Overview

Persei is an animated top menu bar for iOS applications, written in Swift. It provides a customizable and interactive menu that appears from the top of the screen, allowing users to switch between different views or categories within an app.

Pros

  • Smooth and visually appealing animations
  • Highly customizable appearance and behavior
  • Easy integration with existing iOS projects
  • Written in Swift, providing better performance and type safety

Cons

  • Limited to iOS platform only
  • May require additional effort to adapt to complex app structures
  • Potential performance impact on older devices due to animations
  • Limited documentation and examples for advanced use cases

Code Examples

  1. Basic setup of Persei menu:
let menu = MenuView()
menu.delegate = self
menu.items = ["Home", "Profile", "Settings", "About"]
view.addSubview(menu)
  1. Customizing menu appearance:
menu.backgroundColor = .systemBlue
menu.highlightedBackgroundColor = .systemIndigo
menu.textColor = .white
menu.highlightedTextColor = .yellow
menu.font = UIFont.systemFont(ofSize: 16, weight: .medium)
  1. Implementing delegate methods:
extension ViewController: MenuViewDelegate {
    func menu(_ menu: MenuView, didSelectItemAt index: Int) {
        print("Selected item at index: \(index)")
        // Handle menu item selection
    }
}

Getting Started

  1. Install Persei using CocoaPods by adding the following to your Podfile:
pod 'Persei'
  1. Import Persei in your Swift file:
import Persei
  1. Create and configure a MenuView instance:
let menu = MenuView()
menu.delegate = self
menu.items = ["Item 1", "Item 2", "Item 3"]
view.addSubview(menu)

// Position the menu at the top of the screen
menu.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    menu.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
    menu.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    menu.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    menu.heightAnchor.constraint(equalToConstant: 44)
])
  1. Implement the MenuViewDelegate methods to handle user interactions.

Competitor Comparisons

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

Pros of folding-cell

  • More versatile animation options, allowing for complex folding effects
  • Supports both Swift and Objective-C, making it accessible to a wider range of developers
  • Includes a demo app with multiple examples, facilitating easier implementation

Cons of folding-cell

  • Slightly more complex setup and configuration compared to Persei
  • May have a higher performance impact due to the intricate animations
  • Less focused on a specific use case, potentially requiring more customization

Code Comparison

Persei (Swift):

let persei = Persei(frame: view.bounds)
persei.dataSource = self
persei.delegate = self
view.addSubview(persei)

folding-cell (Swift):

let cell = FoldingCell()
cell.delegate = self
cell.itemCount = 2
cell.foregroundView = customView
cell.backgroundView = anotherCustomView

Both libraries offer elegant UI components for iOS, but folding-cell provides more complex animations at the cost of slightly increased setup complexity. Persei focuses on a specific pull-to-refresh style menu, while folding-cell offers a broader range of folding cell animations for various use cases.

:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion

Pros of expanding-collection

  • More visually appealing with 3D-like card expansion effect
  • Supports both vertical and horizontal layouts
  • Includes a demo app with sample implementation

Cons of expanding-collection

  • Limited to UICollectionView, while Persei works with UITableView and UICollectionView
  • Less customizable in terms of animation and appearance
  • Requires more setup and configuration compared to Persei's simpler implementation

Code Comparison

Persei:

let menu = PerseiBridge()
menu.delegate = self
menu.datasource = self
tableView.addSubview(menu)

expanding-collection:

let layout = ExpandingCollectionViewLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.register(ExpandingCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
view.addSubview(collectionView)

Summary

expanding-collection offers a more visually striking effect with its 3D-like card expansion, while Persei provides a simpler implementation and greater flexibility in terms of view types. expanding-collection may be better suited for projects requiring a more elaborate visual presentation, whereas Persei might be preferable for simpler, more customizable implementations across different view types.

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

Pros of animated-tab-bar

  • More customizable animations and icon styles
  • Supports both Swift and Objective-C
  • Larger community and more frequent updates

Cons of animated-tab-bar

  • Slightly more complex implementation
  • May require more system resources due to advanced animations
  • Less intuitive for simple tab bar implementations

Code Comparison

animated-tab-bar:

let tabBar = RAMAnimatedTabBarController()
let item1 = RAMAnimatedTabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
item1.animation = RAMBounceAnimation()
tabBar.viewControllers = [homeVC]
tabBar.animatedItems = [item1]

Persei:

let menu = MenuView()
menu.items = [MenuItem]()
menu.delegate = self
self.view.addSubview(menu)

Both libraries offer unique approaches to enhancing tab bar functionality in iOS applications. animated-tab-bar focuses on providing rich, customizable animations for tab bar items, while Persei emphasizes a pull-to-refresh style menu system. The choice between the two depends on the specific design requirements and user experience goals of your application.

5,370

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.

Pros of Koloda

  • Specialized for Tinder-like card swiping interactions
  • More comprehensive documentation and usage examples
  • Higher number of stars and forks, indicating greater community adoption

Cons of Koloda

  • Limited to card-based UI interactions
  • May require more setup for basic functionality
  • Larger codebase, potentially increasing app size

Code Comparison

Persei (Menu setup):

let menu = PerseiBurger(frame: frame)
menu.delegate = self
menu.dataSource = self
view.addSubview(menu)

Koloda (Card setup):

let kolodaView = KolodaView(frame: frame)
kolodaView.dataSource = self
kolodaView.delegate = self
view.addSubview(kolodaView)

Both repositories offer UI components for iOS applications, but they serve different purposes. Persei focuses on creating customizable menu interfaces, while Koloda specializes in Tinder-like card swiping interactions. Persei is more lightweight and easier to implement for simple menu structures, whereas Koloda provides a more robust solution for card-based UIs with gesture recognition. The choice between the two depends on the specific requirements of your iOS application.

This component implements transition animation to crumble view-controller into tiny pieces.

Pros of StarWars.iOS

  • Offers a visually appealing and interactive Star Wars-themed animation
  • Demonstrates advanced custom view transitions and animations
  • Provides a complete, themed demo application

Cons of StarWars.iOS

  • More specialized and less reusable compared to Persei
  • Limited to a specific theme, which may not fit all projects
  • Larger codebase due to its comprehensive demo nature

Code Comparison

StarWars.iOS (Animation setup):

func setupAnimationItems() {
    let animationItem = AnimationItem(icon: UIImage(named: "Death-Star")!, title: "Death Star", color: UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 1))
    animationItems.append(animationItem)
    // ... more items added
}

Persei (Menu setup):

let menu = MenuView()
menu.items = [
    MenuItem(title: "MUSIC", image: UIImage(named: "menu_music_ico")!),
    MenuItem(title: "FILMS", image: UIImage(named: "menu_films_ico")!),
    // ... more items added
]

Both repositories showcase Yalantis' expertise in creating visually stunning iOS animations. While StarWars.iOS offers a more specialized, themed experience, Persei provides a more versatile and reusable menu component. The code snippets demonstrate the different approaches to setting up UI elements in each project.

Animated side menu with customizable UI

Pros of Side-Menu.iOS

  • Simpler implementation for basic side menu functionality
  • Lightweight and focused on a single feature
  • Easier to integrate into existing projects

Cons of Side-Menu.iOS

  • Less customizable compared to Persei's menu options
  • Limited to side menu functionality, while Persei offers more versatile menu placement
  • May require additional work for advanced animations or transitions

Code Comparison

Side-Menu.iOS:

let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.leftMenuNavigationController = menuLeftNavigationController

Persei:

let menu = MenuView()
menu.items = [MenuItem]()
scrollView.addSubview(menu)
menu.snp.makeConstraints { make in
    make.edges.equalTo(scrollView)
}

The Side-Menu.iOS code focuses on setting up a side menu navigation controller, while Persei's code demonstrates the creation and customization of a menu view that can be placed in various positions within the app's interface.

Both libraries offer unique approaches to menu implementation in iOS apps, with Side-Menu.iOS being more specialized for side menus and Persei providing a more flexible solution for different menu styles and placements.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Persei

Build Status License

Preview

Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift!

Made in Yalantis.

Check this project on Dribbble

Check this project on Behance

Supported Swift versions

Swift VersionPersei
1.x1.1
2.x2.0
3.x3.0
4.x3.1
5.x4.0

Installation

CocoaPods

use_frameworks!

pod 'Persei', '~> 4.0'

Carthage

github "Yalantis/Persei" ~> 4.0

Manual Installation

For application targets that do not support embedded frameworks, such as iOS 7, Persei can be integrated by including source files from the Persei folder directly, optionally wrapping the top-level types into struct Persei to simulate a namespace. Yes, this sucks.

  1. Add Persei as a submodule by opening the Terminal, cd-ing into your top-level project directory, and entering the command git submodule add https://github.com/yalantis/Persei.git
  2. Open the Persei folder, and drag Persei.xcodeproj into the file navigator of your app project.
  3. In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
  4. Ensure that the deployment target of Persei.framework matches that of the application target.
  5. In the tab bar at the top of that window, open the "Build Phases" panel.
  6. Expand the "Target Dependencies" group, and add Persei.framework.
  7. Expand the "Link Binary With Libraries" group, and add SideMenu.framework
  8. Click on the + button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add Persei.framework.

Usage

Import Persei module

import Persei

Init

let menu = MenuView()    
tableView.addSubview(menu)

Configuring items

In order to set items you need to instantiate array of MenuItem:

let items = feedModes.map { mode: SomeYourCustomFeedMode -> MenuItem in
	return MenuItem(image: mode.image)
}

menu.items = items

Handling selection

You can specify selected item manually:

menu.selectedIndex = 3

Note, that selectedIndex declared as Int? and will be nil in case of menu.items = nil.

Also, you can implement MenuViewDelegate to be notified about selection change:

// during init
menu.delegate = self

// actual implementation
extension FeedViewController: MenuViewDelegate {
    func menu(menu: MenuView, didSelectItemAt index: Int) {
    	dataSource.mode = feedModes[index] // alter mode of dataSource

    	tableView.reload() // update tableView
    }
}

Reveal menu manually

Menu can be reveal as a result of button tap:

func menuButtonSelected(sender: UIControl) {
	menu.revealed = !menu.revealed

	// or animated
	menu.setRevealed(true, animated: true)
}

Content Gravity

Use contentViewGravity to control sticking behavior. There are 3 available options:

  • Top: contentView sticked to the top position of the view
  • Center: contentView is aligned to the middle of the streched view
  • Bottom: contentView sticked to the bottom

Customization

MenuItem declares set of attributes, that allow you to customize appearance of items:

struct MenuItem {
    var image: UIImage // default image
    var highlightedImage: UIImage? // image used during selection

    var backgroundColor: UIColor // default background color
    var highlightedBackgroundColor: UIColor // background color used during selection

    var shadowColor: UIColor // color of bottom 2px shadow line
}

Also you're free to configure background of MenuView by utilizing backgroundColor or backgroundImage. Note, that image should be resizeable:

let menu = MenuView()
menu.backgroundImage = UIImage(named: "top_menu_background")

Advanced customization

  • Can I place the UIImageView instead?
  • Sure! Just subclass / use StickyHeaderView directly. It offers layout, positioning and reveal control. All you have to do is to assign your custom view (animated nian-cat UIImageView) to contentView:
let headerView = StickyHeaderView()
let imageView = UIImageView(...)

headerView.contentView = imageView

Obviously, your custom view can have heigh different from default:

headerView.contentHeight = image.size.height

As well as control distance to trigger open/close of the header:

headerView.threshold = 0.5

Threshold is a float value from 0 to 1, specifies how much user needs to drag header for reveal.

Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the animation.

P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!

License

The MIT License (MIT)

Copyright © 2017 Yalantis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.