美文网首页iOS开发
iOS开发遇到的小问题 (未完待续......)

iOS开发遇到的小问题 (未完待续......)

作者: insence | 来源:发表于2017-01-05 17:10 被阅读41次
    • tablview点击push到下一个页面,pop出来时位置下移了 ,解决办法:
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    • 取消tableview点击时的灰色效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    • 隐藏tabelview的分割线
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    • tableview分割线从头开始
    _tableView.separatorInset = UIEdgeInsetsZero;
    
    • tableview取消区头停滞效果
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
        
        CGFloat sectionHeaderHeight = sectionHead.height;
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView;.contentOffset.y>=0)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        }
        else if(scrollView.contentOffset.y>=sectionHeaderHeight)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
    
    • 防止scrollView手势和侧滑手势冲突
    [scrollView.panGestureRecognizerrequireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
    
    • ScrollView不能划到viewController顶部
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    • 滑动隐藏navigationbar
    self.navigationController.hidesBarsOnSwipe=YES;
    
    • label设置首行缩进
    label.attributedText = [self setLabelIndent:15 text:@"这里是内容"];
    // indent是字体的大小, text是内容
    -(NSAttributedString *)setLabelIndent:(CGFloat)indent text:(NSString *)text {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.firstLineHeadIndent = indent * 2;
        NSDictionary *attributeDic = @{NSParagraphStyleAttributeName : paragraphStyle};
        NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:text attributes:attributeDic];
        
        return attrText;
    }
    
    • 取消btn点击高亮状态,解决办法:
    _btn.adjustsImageWhenHighlighted = NO;
    
    • iOS系统 POP 手势与 UIScrollView 手势冲突的解决方法
    新建一个 ScrollView 继承 UIScrollView
    
    重写 gestureRecognizer:(UIGestureRecognizer)gestureRecognizer  shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer)otherGestureRecognizer
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
       // 判断 otherGestureRecognizer 是不是系统 POP 手势
       if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UILayoutContainerView")]) {
    
           // 判断 POP 手势的状态是 begin 还是 fail,同时判断 scrollView 的 ContentOffset.x 是不是在最左边
           if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && self.contentOffset.x == 0) {
               return YES;
           }
       }
       return NO;
    }
    
    • UIImagePickerController拍照之后图片旋转的问题 ,解决办法:
    // 拍照选择照片协议方法
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        
        NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
        if ([type isEqualToString:@"public.image"]) {
            UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
            UIImageOrientation imageOrientation=image.imageOrientation;
            if(imageOrientation!=UIImageOrientationUp)
                {
                UIGraphicsBeginImageContext(image.size);
                [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
                image = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();
                }
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS开发遇到的小问题 (未完待续......)

        本文链接:https://www.haomeiwen.com/subject/xepzvttx.html