常用代码(一)

2018-02-05  本文已影响16人  活最好的自己
  1. MJFooter下拉刷新时候, 不显示刷新中和没有数据等的文字
        MJRefreshAutoStateFooter *footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
            [weakSelf requestMatchScheduleMoreDataNoLoadingView];
        }];
        [footer setTitle:@"" forState:MJRefreshStateNoMoreData];
        [footer setTitle:@"" forState:MJRefreshStateRefreshing];
  1. NSUrl 解析 url scheme
- (void)test3{
    NSString *urlStr = @"https://www.jianshu123.com/p/d32351b5c1dfs#aaa?wd=UIScrollview嵌套&rsv_spt=1&rsv_iqid=0xd3e7235e000812de&issp=1&f=3&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=1";
    
    NSCharacterSet *allowedCharacters = [NSCharacterSet URLQueryAllowedCharacterSet];
    NSString *encodedUrl = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
    NSURL *url = [NSURL URLWithString:encodedUrl];
    
    NSDictionary *dictM = [NSMutableDictionary dictionaryWithCapacity:2];
    NSArray *arrayQuery = [url.query componentsSeparatedByString:@"&"];
    for (NSString *paramsStr in arrayQuery) {
        NSArray *keyValueArray = [paramsStr componentsSeparatedByString:@"="];
        if ([keyValueArray isKindOfClass:[NSArray class]] && keyValueArray.count == 2) {
            [dictM setValue:keyValueArray[1] forKey:keyValueArray[0]];
            NSLog(@"%@---%@",keyValueArray[0],keyValueArray[1]);
        }
    }
}
  1. 键盘弹起时, 视图跟着动画
- (void)viewDidLoad {
    [super viewDidLoad];
    [self bindActiveAndAppear];
}

- (void)bindActiveAndAppear
{
    @weakify(self);
    [[RACSignal combineLatest:@[RACObserve(self, appear),RACObserve([PTVAppStatusModule sharedInstance], appActive)] reduce:^id (NSNumber* appear, NSNumber* active){
        return @(appear.boolValue && active.boolValue);
    }] subscribeNext:^(NSNumber* x) {
        @strongify(self);
        if(x.boolValue) {
            [self an_subscribeKeyboardWithAnimations:^(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing) {
                [self.groupMsgView mas_updateConstraints:^(MASConstraintMaker *make) {
                    if (isShowing) {
                        make.bottom.equalTo(self.view).offset(-keyboardRect.size.height);
                    } else {
                        make.bottom.equalTo(self.view);
                    }
                }];
                [self.view layoutIfNeeded];
            } completion:nil];
        } else {
            [self an_unsubscribeKeyboard];
        }
    }];
}
  1. 只响应当前视图中的热区的事件
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

    if (_eggTaskView && !_eggTaskView.hidden ) {
        CGPoint newpoint = [self convertPoint:point toView:_eggTaskView.introBtn]; 
        
        if (CGRectContainsPoint(_eggTaskView.introBtn.bounds, newpoint)) {
            return [super hitTest:point withEvent:event];
        }
    }
    return nil;
}
上一篇 下一篇

猜你喜欢

热点阅读