1. weex SDK中Slider,ScrollView等滚动视图上进度条滑动冲突
- 创建scrollview子类
//fml fix
@interface FMLScrollView : UIScrollView
@end
@implementation FMLScrollView
- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:NSClassFromString(@"FMLPlayerSliderView")] || [view isKindOfClass:NSClassFromString(@"HVMPBottomView")]) {
return NO;
}
return YES;
}
- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view
{
if ([view isKindOfClass:NSClassFromString(@"FMLPlayerSliderView")]) {
return NO;
}
else {
return YES;
}
}
@end
设置scrollview的两个属性:
// self.canCancelContentTouches = YES; self.delaysContentTouches = NO;
在slider视图中添加pan手势
- (void)panAction:(UIPanGestureRecognizer *)pan {
if (self.duration <= 0.1 || isnan(self.duration)) {
return;
}
BOOL _canLeft = YES;
BOOL _canRight = YES;
//点相对于上一个点的位置
CGPoint moviePoint = [pan translationInView:pan.view];
CGFloat curY = pan.view.center.x + moviePoint.x;
//侧滑的范围
CGFloat instance = self.frame.size.width;
if (pan.view.frame.origin.x <= 0 && moviePoint.x <= 0) {
//禁止左划的情况(在最左边时)
_canLeft = NO;
}
if (pan.view.frame.origin.x >= (instance - _leftWidth - _rightWidth) && moviePoint.x >= 0) {
//禁止右划得情况(在最右边时)
_canRight = NO;
}
if (_canLeft & _canRight){
//移动
if (curY <= _leftWidth) {
pan.view.center = CGPointMake(_leftWidth, pan.view.center.y);
}
else if (curY >= (instance - _rightWidth)) {
pan.view.center = CGPointMake(instance - _rightWidth, pan.view.center.y);
}
else {
pan.view.center = CGPointMake(pan.view.center.x + moviePoint.x, pan.view.center.y);
}
}
//每次都需要复位
[pan setTranslation:CGPointZero inView:pan.view];
//松开手指时判断滑动趋势让其归位
if (pan.state == UIGestureRecognizerStateBegan) {
if ([self.delegate respondsToSelector:@selector(sliderSeekBeginWithDuration:)]) {
[self.delegate sliderSeekBeginWithDuration:self.duration];
}
_knobHighlightImageView.hidden = NO;
[UIView animateWithDuration:0.4 animations:^{
_knobHighlightImageView.transform = CGAffineTransformMakeScale(1.5, 1.5);
}];
}
else if (pan.state == UIGestureRecognizerStateEnded) {
CGFloat finalTime = 0;
if (pan.view.frame.origin.x <= 0) {
finalTime = 0;
} else if(pan.view.frame.origin.x >= (instance - _leftWidth - _rightWidth)){
finalTime = self.duration;
}
else {
CGFloat sliderWidth = self.bounds.size.width - _leftWidth - _rightWidth;
CGFloat curPercent = (pan.view.frame.origin.x - 0) / sliderWidth;
finalTime = curPercent * self.duration;
}
if ([self.delegate respondsToSelector:@selector(sliderSeekEnd:duration:)]) {
[self.delegate sliderSeekEnd:finalTime duration:self.duration];
}
[UIView animateWithDuration:0.4 animations:^{
_knobHighlightImageView.hidden = YES;
_knobHighlightImageView.transform = CGAffineTransformIdentity;
}];
}
}
2. 在#import "WXThreadSafeMutableArray.h"
中数组越界
// fml fix
- (id)objectAtIndex:(NSUInteger)index
{
__block id obj;
if (![WXUtility threadSafeCollectionUsingLock]) {
dispatch_sync(_queue, ^{
if (index < _array.count) {
obj = _array[index];
}
});
} else {
if (WX_SYS_VERSION_GREATER_THAN(@"10.0")) {
os_unfair_lock_lock(&_osUnfairLock);
if (index < _array.count) {
obj = _array[index];
}
os_unfair_lock_unlock(&_osUnfairLock);
} else {
pthread_mutex_lock(&_safeThreadArrayMutex);
if (index < _array.count) {
obj = _array[index];
}
pthread_mutex_unlock(&_safeThreadArrayMutex);
}
}
return obj;
}
// fml fix
- (void)removeObject:(id)anObject;
{
if (![WXUtility threadSafeCollectionUsingLock]) {
dispatch_barrier_async(_queue, ^{
[_array removeObject:anObject];
});
} else {
if (WX_SYS_VERSION_GREATER_THAN(@"10.0")) {
os_unfair_lock_lock(&_osUnfairLock);
[_array removeObject:anObject];
os_unfair_lock_unlock(&_osUnfairLock);
} else {
pthread_mutex_lock(&_safeThreadArrayMutex);
[_array removeObject:anObject];
pthread_mutex_unlock(&_safeThreadArrayMutex);
}
}
}
// fml fix
#pragma mark
#pragma mark - Storage Index method
- (void)updateIndexForKey:(NSString *)key {
if ([[self indexs] containsObject:key]) {
[[self indexs] removeObject:key];
}
[[self indexs] addObject:key];
[self write:[[self indexs] copy] toFilePath:[WXStorageModule indexFilePath]];
}
- (void)removeIndexForKey:(NSString *)key {
if ([[self indexs] containsObject:key]) {
[[self indexs] removeObject:key];
}
[self write:[[self indexs] copy] toFilePath:[WXStorageModule indexFilePath]];
}