High-performance danmaku with click event, reusable items and customize configurations.
- Except UI operations in main-thread, other operations are in different dispatch queues.
- Followed producer-cosumer pattern with pthread lib.
- Defined delegate protocol to handle click response or other events.
- Methods to register resuable item. Defined FXDanmakuItem class to custom your own item by inheriting it.
- 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.
- Easy to use. Just three control: start(resume), pause, stop. Except that, most methods are thread-safe.
- Adaptation to the change of device orientaion.
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.
Last thing, drag IBOutlet property to setup your custom danmakuItem.
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];
}
// 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;
}
FXDanmaku requires iOS 7.0+
.
-
Add these lines below to your Podfile
platform :ios, 'xxx' target 'xxx' do pod 'FXDanmaku', '~> 1.0.0' end
-
Install the pod by running
pod install
Drag FXDanmaku
document to your project
FXDanmaku is provided under the MIT license. See LICENSE file for details.