Skip to content

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

License

Notifications You must be signed in to change notification settings

CJWDevelop/FXDanmaku

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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 built and ran 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];
}

##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.2'
    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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 92.2%
  • Shell 7.4%
  • Ruby 0.4%