突发想着给直播课堂的直播课上加弹幕
1.label宽度高度自适应
+ (CGSize)sizeWithString:(NSString*)string font:(UIFont*)font constraintSize:(CGSize)constraintSize
{
CGSizestringSize =CGSizeZero;
NSDictionary*attributes =@{NSFontAttributeName:font};
NSIntegeroptions =NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin;
CGRectstringRect = [string boundingRectWithSize:constraintSizeoptions:optionsattributes:attributescontext:NULL];
stringSize = stringRect.size;
returnstringSize;
}通过boundingRectWithSize这个方法可以准确得到str的长度宽度
2.一个简单实现弹幕(在对啊直播课堂试了试很简单)
3.负责的弹幕,考虑的问题比较多
考虑条数,碰撞,弹幕暂停及恢复等问题