Giter Club home page Giter Club logo

fxdanmaku's Introduction

FXDanmaku

中文 iOS 7.0+ pod compatible License

High-performance danmaku with click event, reusable items and customize configurations.

Features

  1. Except UI operations in main-thread, other operations are in different dispatch queues.
  2. Followed producer-cosumer pattern with pthread lib.
  3. Defined delegate protocol to handle click response or other events.
  4. Methods to register resuable item. Defined FXDanmakuItem class to custom your own item by inheriting it.
  5. Many configurations to meet your product's requirements. Such as, the velocity of item, the order to insert item, the direction of item movement and so on.
  6. Easy to use. Just three control: start(resume), pause, stop. Except that, most methods are thread-safe.
  7. Adaptation to the change of device orientaion.

Preview

Example

Setup danmaku view:

// Configuration
FXDanmakuConfiguration *config = [FXDanmakuConfiguration defaultConfiguration];
config.rowHeight = [DemoDanmakuItem itemHeight];
config.dataQueueCapacity = 500;
config.itemMinVelocity = 80;  // set random velocity between 80 and 120 pt/s
config.itemMaxVelocity = 120;
self.danmaku.configuration = config;

// Delegate
self.danmaku.delegate = self;

// Reuse
[self.danmaku registerNib:[UINib nibWithNibName:NSStringFromClass([DemoDanmakuItem class]) bundle:nil]
   forItemReuseIdentifier:[DemoDanmakuItem reuseIdentifier]];
[self.danmaku registerClass:[DemoBulletinItem class]
     forItemReuseIdentifier:[DemoBulletinItem reuseIdentifier]];

Add data:

// add data for danmaku view to present
DemoDanmakuItemData *data = [DemoDanmakuItemData data];
[self.danmaku addData:data];

// start running
if (!self.danmaku.isRunning) {
	[self.danmaku start];
}

Handle click in delegate method:

- (void)danmaku:(FXDanmaku *)danmaku didClickItem:(FXDanmakuItem *)item withData:(DemoDanmakuItemData *)data {
	// handle click event here
}

More examples in FXDanmakuDemo.xcworkspace.

Demo build succeed in Xcode8.

Q&A

1. Relationships among rowHeight、estimatedRowSpace and rowSpace.

2. How to create your danmakuItem by nib.

Last thing, drag IBOutlet property to setup your custom danmakuItem.

3. Adaptation to the change of device orientaion.

Only when your danmaku view's height will change in different device orientaion, should you do a little work to adapt. Otherwise, you won't need to add any codes. Let's say, your danmaku view's height is 100pt in portrait, but is 200pt in lanscape. Then add codes below in your controller.

For iOS8 And Later

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
	[self.danmaku pause];
	[self.danmaku cleanScreen];

	[coordinator animateAlongsideTransition:nil
								 completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
                                 	// resume danmaku after orientation did change
                                 	[self.danmaku start];
                             	 }];
}

For version lower than iOS8

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
		[self.danmaku pause];
		[self.danmaku cleanScreen];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
		[self.danmaku start];
}

4. How to limit the capacity of the data queue to the FXDanmaku view?

// By setting the FXDanmakuConfiguration
FXDanmakuConfiguration *config = [FXDanmakuConfiguration defaultConfiguration];
// The number of FXDanmakuItemData that FXDanmaku view can hold at maximum count.
config.dataQueueCapacity = 500;
// Beyond this value, the data will be discarded.

In addition, you still have chance to decide which data can be added into the queue when data quque is full through delegate method.

- (BOOL)shouldAddDanmakuItemDataWhenQueueIsFull:(FXDanmakuItemData *)data {
	// Keep adding data with high priority, even the number of the data in queue reaches maximum count
	return FXDataPriorityHigh == data.priority;
}

Requirements

FXDanmaku requires iOS 7.0+.

Installation

Cocoapods(iOS7+)

  1. Add these lines below to your Podfile

    platform :ios, 'xxx'
    target 'xxx' do
      pod 'FXDanmaku', '~> 1.0.0'
    end
    
  2. Install the pod by running pod install

Manually(iOS7+)

Drag FXDanmaku document to your project

License

FXDanmaku is provided under the MIT license. See LICENSE file for details.

fxdanmaku's People

Contributors

shawnfoo avatar jiyue00 avatar

Watchers

James Cloos avatar  avatar

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.