WEEX遇到的问题,源码改动备注 (二)

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]];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,054评论 3 119
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,361评论 1 14
  • 既然情色是小说的一部分,那么默认情色描写应该是文学性的,是为整个小说服务的,而不是纯粹的感官刺激——或者我们不妨说...
    黑色玫瑰d阅读 4,344评论 1 9
  • 本来打算昨晚弄完手绘作业但是… 到差不多十一点就上床了WN还在继续作业 玩会手机继续作业那时候的我在躺床上偷拍
    只不过是一场生活阅读 1,526评论 1 1
  • Ⅰ. “只要你想成功,从现在开始永远都不晚。”多少人靠这碗鸡汤度过了一年又一年,频繁安慰自己今年的一事无成,立志下...
    北方阿徐阅读 3,911评论 1 0

友情链接更多精彩内容