Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]:CYLTabBar frame可能在某些系统版本下设置错误 #591

Open
dbcrystal opened this issue Jul 1, 2022 · 0 comments
Open

[bug]:CYLTabBar frame可能在某些系统版本下设置错误 #591

dbcrystal opened this issue Jul 1, 2022 · 0 comments
Assignees
Labels

Comments

@dbcrystal
Copy link

dbcrystal commented Jul 1, 2022

Base Info for this issue

  1. Version:Latest Version as here
  2. Language of App :Objective-C
  3. iOS System Version:iOS12
  4. Prototype(是否是真机):YES
  5. Issue Type:Bug、Q-A

1. How to reproduce the problem.

设备:iOS 12,CYL_IS_IPHONE_X为true(刘海屏)
逻辑:自定义页面transition动画,设置from页面需要在to页面推出时进行缩放
现象:CYLTabBar的originY被拉高

原因:在新页面Push出来时,-[CYLTabBarController viewWillLayoutSubviews]被调用,若CYL_IS_IPHONE_X为true则重设self.tabbar的frame。此时获取的self.view.frame.size.height为缩放后的高度尺寸。

这个frame在iOS 12及以上设备都会被错误设置,但在高版本系统中,在-[CYLTabBarController viewWillLayoutSubviews]调用后,系统会再次调用-[UITabBarController _layoutContainerView],这个函数中会重新设置一次tabBar的frame,导致问题在高版本会被修复。-[UITabBarController _layoutContainerView]的这段修复逻辑在iOS 12设备上没有被执行。

2. Please help me in this way.

-[CYLTabBarController viewWillLayoutSubviews]中设置tabBarFrame的逻辑是否能被移除?是否能使用autoLayout方法进行布局?
我翻阅了这段函数前后的日志,发现:
frame.origin.y = self.view.frame.size.height - tabBarHeight;
这行代码在前几年曾被短暂改为:
frame.origin.y = [UIScreen mainScreen].bounds.size.height - tabBarHeight;
后又被改回。这里当初的背景是?

3. Here is a Demo.

- (void)openAnimation:(id <UIViewControllerContextTransitioning>)transitionContext{
    UIModalPresentationStyle style =  [transitionContext presentationStyle];
    
    UIView *container = [transitionContext containerView];
    
    UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
    UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
    
    [container addSubview:fromView];
    
    self.bgView.frame = container.bounds;
    self.bgView.alpha = 0;
    [container addSubview:self.bgView];
    
    [container addSubview:toView];
    
    NSTimeInterval duration = 0.5f;
    fromView.userInteractionEnabled = NO;
    toView.userInteractionEnabled = NO;
    container.backgroundColor = UIColor.clearColor;
    
    void(^finishBlock)(void) = ^{
        
        [transitionContext completeTransition:!transitionContext.transitionWasCancelled];
        fromView.transform = CGAffineTransformIdentity;
        toView.transform = CGAffineTransformIdentity;
        toView.userInteractionEnabled = YES;
        fromView.userInteractionEnabled = YES;
        fromView.alpha = 1;
        toView.alpha = 1;
        container.backgroundColor = UIColor.clearColor;
    };

    container.backgroundColor = UIColor.blackColor;
    toView.transform = CGAffineTransformMakeTranslation(toView.frame.size.width, 0);
            
    [UIView animateWithDuration:duration delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
                
        fromView.transform = CGAffineTransformMakeScale(self.scale, self.scale);
        toView.transform = CGAffineTransformIdentity;
        self.bgView.alpha = 1;
    } completion:^(BOOL finished) {
        finishBlock();
    }];
}

4. Here is my Debug log


@dbcrystal dbcrystal added the bug label Jul 1, 2022
@dbcrystal dbcrystal changed the title [bug]:CYLTabBar frame [bug]:CYLTabBar frame可能在某些系统版本下设置错误 Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants