“This is the 15th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

preface

  1. IOS Navigation updates constraints in the form of animations

Application scenario: Filter view show and hide with animation to improve user experience

  1. Use dividedBy for nine-grid layout
  2. I’ll post a sample of the aspect ratio constraint

I navigation updates constraints in the form of animations

After changing the constraint, use the method layoutIfNeeded in the animation block to achieve a general animation effect

1.1 Implementation Mode

  1. After changing the constraint, use the method layoutIfNeeded in the animation block to achieve a general animation effect.

  1. Facebook’s animation framework pop

Github.com/facebookarc… Facebook Pop is a separate Animation scheme from Core Animation based on CADisplayLink(CVDisplayLink for Mac)

1.2 Implementation Code

- (void)setupProductCategoryTreeFilterViewHidden:(BOOL)hidden{
    float hiddenTime = 0.5;
    WS(weakSelf);

               if (hidden) {// Dispatch_after hiddenTime is required for animation
                   
                   
                   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(hiddenTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{


                       [weakSelf.ProductCategoryTreeFilterView setHidden:hidden];
                       
                       
                   });

                   [self.ProductCategoryTreeFilterView mas_updateConstraints:^(MASConstraintMaker *make) {
                       make.left.equalTo(weakSelf).offset(kAdjustRatio(SCREENW));
                       make.right.equalTo(weakSelf).offset(kAdjustRatio(SCREENW));
                   }];
                   
                   
               }else{// Set hidden to display
                   
                   [weakSelf.ProductCategoryTreeFilterView setHidden:hidden];

    
                   [self.ProductCategoryTreeFilterView mas_updateConstraints:^(MASConstraintMaker *make) {
                       make.left.equalTo(weakSelf).offset(kAdjustRatio(50));
                       make.right.equalTo(weakSelf).offset(kAdjustRatio(0));
                   }];
                   
               }

// Navigation updates constraints with animation
    
    [self setNeedsUpdateConstraints];// // tells self the constraint needs to be updated

    [self updateConstraintsIfNeeded];// // Calling this method tells self to check if the constraint needs to be updated and if so, add an animation effect to take effect


    [UIView animateWithDuration:hiddenTime animations:^{
        

        
        [self layoutIfNeeded];// gengxin frame
        

        
    }];
    
    


}

Copy the code
  • The core code
        if (hidden) {/ / hide
            
            
            [self.ProductCategoryTreeFilterView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(weakSelf).offset(kAdjustRatio(SCREENW));
                make.right.equalTo(weakSelf).offset(kAdjustRatio(SCREENW));
            }];
            
            
        }else{/ / show
            
            
            [self.ProductCategoryTreeFilterView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(weakSelf).offset(kAdjustRatio(50));
                make.right.equalTo(weakSelf).offset(kAdjustRatio(0));
            }];
            
        }
// Navigation updates constraints with animation
    
    [self setNeedsUpdateConstraints];// // tells self the constraint needs to be updated

    [self updateConstraintsIfNeeded];// // Calling this method tells self to check if the constraint needs to be updated and if so, add an animation effect to take effect

    [UIView animateWithDuration:hiddenTime animations:^{
        
            
        
        [self layoutIfNeeded];// gengxin frame
        

        
    }];
    

Copy the code

II Use dividedBy to achieve nine-grid layout

I’ll retrieve all the navigation I’ll retrieve

/** I'll take you next
- (void)setModel:(QCTtodoContentTableViewCellModel *)model{
    _model = model;
    
    // Build child attempts
    QCTsubStatusBtnView * lasttmp;
    NSInteger col = 4;/ / the total number of columns
    for (int i = 0; i<col; model.models) {
        QCTtodoStatusInfoModel *obj = model.models[i];
        QCTsubStatusBtnView * tmp = [QCTsubStatusBtnView new];
        tmp.model = obj;
        
        [self addSubview:tmp];
        __weak __typeof__(self) weakSelf = self; [tmp mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(weakSelf);  make.width.equalTo(weakSelf).dividedBy(col);// make.left.equalTo(tmp.mas_width).multipliedBy(i);
            
            if (i%col == 0) {
                make.left.equalTo(weakSelf);

            }else{
                make.left.equalTo(lasttmp.mas_right);

            }
            
// make.centerX.equalTo(tmp.mas_width).multipliedBy(i*2+1);make.bottom.equalTo(weakSelf); make.top.equalTo(weakSelf); }]; lasttmp = tmp; i++; }}Copy the code

III Perform view aspect ratio constraints

    [self.kuangImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.tishiLabel.mas_bottom).offset(kAdjustRatio(0));        
        make.left.right.offset((0));
//multipliedBy
        //dividedBy
        // Set the height/width to 388:375.0
     make.height.equalTo(weakSelf.view.mas_width).multipliedBy(388/375.0);
       
        
    }];

Copy the code

Kunnan.blog.csdn.net/article/det…

IOS13 scanning id & bank card information recognition; Id card identification (positive and negative); Rectangular edge recognition; Custom certificate camera (demo source)

see also

IOS set the click event priority of tableView to lower than the selected event of cell.

Blog.csdn.net/z929118967/…

Due to space reasons, more content please pay attention to # small program: iOS reverse, only for you to present valuable information, focus on mobile technology research field; For more services and advice, please follow # publicid: iOS Reverse.