美文网首页
iOS UIScrollview UICollectionVie

iOS UIScrollview UICollectionVie

作者: 老猫_2017 | 来源:发表于2020-04-24 13:57 被阅读0次
    1. ContentInsetAdjustmentBehavior
      会影响 contentInset 的变化,设置成 never 完全,手动控制,否则,某些动画,会变化的比较奇怪

    2. UICollectionView 直接执行 reloaddata 之后, 不能及时的更新 contenInset , 解决方法有2个,一个执行

    [self.collectionView performBatchUpdates:^() 
    {
    
    } completion:^(BOOL finished) {
        // TODO: Whatever it is you want to do now that you know the contentSize.
    }];
    

    方法2

    [self.collectionView.collectionViewLayout invalidateLayout];
    [self.collectionView.collectionViewLayout prepareLayout];
    

    相关的keybarod 动画

    if  let inputV =  Bundle.main.loadNibNamed("TestView", owner: self, options: nil)?.first as? UIView {
                view.addSubview(inputV)
                inputV.center = view.center
                if let textV = inputV.viewWithTag(2) as? UITextView {
                    textV.inputAccessoryView = inputV
                    textV.delegate = self
                    textV.returnKeyType = .send
                    self.textV = textV
                    self.containerV = inputV
                    self.containerV?.backgroundColor = .red
                }
            }
            
            NotificationCenter.default.rx.notification(UIResponder.keyboardWillShowNotification).subscribe(onNext: {
                [weak self] (notification) in
                let rect = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
                self!.keyboardFrame = rect
                print(rect)
                
            }).disposed(by: disposeBag)
            
            NotificationCenter.default.rx.notification(UIResponder.keyboardWillHideNotification).subscribe(onNext: {
                [weak self] (notification) in
                let rect = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
    //            self!.keyboardFrame = rect
                print(rect)
                
            }).disposed(by: disposeBag)
            
            let tap  = UITapGestureRecognizer()
            view.addGestureRecognizer(tap)
            tap.rx.event.bind { [weak self] (tap) in
                guard let self = self else { return }
    //            self.loginVm.userName.onNext("hhh")
    //            self.view.endEditing(true)
                
                self.textV?.resignFirstResponder()
      
                let r1 = self.view .convert(self.keyboardFrame!, to: nil)
                
                self.view.addSubview(self.containerV!)
                self.containerV!.mgl_top = r1.origin.y
                self.containerV!.translatesAutoresizingMaskIntoConstraints = true
                
                
                UIView.animate(withDuration: 0.24, delay: 0, options: UIView.AnimationOptions(rawValue: 7 << 16), animations: {
                    self.containerV!.mgl_bottom = self.view.mgl_bottom
                }) { (finished) in
                }
            }
    

    scrollview 中的 contentInsert, contentSize, contentOffset 之间的关系
    contentoffset-contentinset

    scrollview contentsize, content offset, content insert

    相关文章

      网友评论

          本文标题:iOS UIScrollview UICollectionVie

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