Git Product home page Git Product logo

Comments (3)

Akateason avatar Akateason commented on July 24, 2024

我的暂时解决方案是先加一个默认flowlayout, 等加载完再切换你的layout. 但这样并没有根治.

from hjcarouseldemo.

panghaijiao avatar panghaijiao commented on July 24, 2024

看一下demo VC,里面有获取curIndexPath的方法

from hjcarouseldemo.

Akateason avatar Akateason commented on July 24, 2024

在预加载时先滚动到某个位置,会有bug, 加载完不会有.
最终我用一个比较绕的方式解决了. set两次layout

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init] ;
    layout.itemSize = CGSizeMake(
                         APP_WIDTH - kFlexOfSide ,
                         APP_HEIGHT - APP_NAVIGATIONBAR_HEIGHT - APP_STATUSBAR_HEIGHT - APP_SAFEAREA_TABBAR_FLEX - kFlexOfSide
                                 ) ;
    [self.collectionView registerNib:[UINib nibWithNibName:@"DetailCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"DetailCollectionCell"] ;
    self.collectionView.collectionViewLayout = layout ;
    self.collectionView.dataSource = self ;
    self.collectionView.delegate = self ;
    self.collectionView.backgroundColor = [UIColor xt_bg] ;
    [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.sendIndex inSection:0]
                                atScrollPosition:UICollectionViewScrollPositionCenteredVertically
                                        animated:NO] ;
    @weakify(self)
    [[RACObserve(self.collectionView, contentOffset)
      throttle:.8]
     subscribeNext:^(id  _Nullable x) {
         @strongify(self)
         PwdItem *currentItem = self.dataSource[self.currentIndex] ;
         self.title = currentItem.name ;
     }] ;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        HJCarouselViewLayout *layout = [[HJCarouselViewLayout alloc] initWithAnim:HJCarouselAnimCarousel1] ;
        layout.visibleCount = 3 ;
        layout.itemSize = CGSizeMake(
                                     APP_WIDTH - kFlexOfSide ,
                                     APP_HEIGHT - APP_NAVIGATIONBAR_HEIGHT - APP_STATUSBAR_HEIGHT - APP_SAFEAREA_TABBAR_FLEX - kFlexOfSide
                                     ) ;
        self.collectionView.collectionViewLayout = layout ;
        
        [self.collectionView selectItemAtIndexPath:[self curIndexPath]
                                          animated:NO                                    scrollPosition:UICollectionViewScrollPositionCenteredVertically] ;
    }) ;

from hjcarouseldemo.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.