为什么第一次将 UIBezierPath 作为遮罩添加到 UIView 时,右侧和底部会出现较小的边距?

问题描述 投票:0回答:1

每次我实例化一个 UIView 并使用 roundSpecificCorners:withRadius: 函数添加一个 UIBezierPath 作为遮罩时,该视图似乎在右侧和底部有较小的边距,导致它没有按预期覆盖整个视图。

@implementation LoginAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Initial setup of the view
    enterEmailView.inputTextField.placeholder = @"Enter Email";
    enterPasswordView.inputTextField.placeholder = @"Enter Password";
}

- (void)viewWillLayoutSubviews{
    // Apply corner rounding on the main view
    [mainViewContainer roundSpecificCorners:UIRectCornerTopLeft | UIRectCornerTopRight withRadius:10.0];
    [super viewWillLayoutSubviews];
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    __weak typeof(self) weakSelf = self;
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        // Apply corner rounding when changing orientation
        UIWindowScene *windowScene = (UIWindowScene *)self.view.window.windowScene;
        UIInterfaceOrientation orientation = windowScene.interfaceOrientation;
        if (UIInterfaceOrientationIsLandscape(orientation)) {
            [weakSelf.mainViewContainer roundSpecificCorners:UIRectCornerTopLeft | UIRectCornerTopRight withRadius:10.0];
        } else {
            [weakSelf.mainViewContainer roundSpecificCorners:UIRectCornerTopLeft | UIRectCornerTopRight withRadius:10.0];
        }
    } completion:nil];
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end

@implementation UIView (CustomLoader)

// Other functions here...

- (void)roundSpecificCorners:(UIRectCorner)corners withRadius:(CGFloat)radius {
    // Apply a layer mask with corner rounding
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)].CGPath;
    self.layer.mask = maskLayer;
    // Adjust the autoresizingMask to allow for size changes
    self.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
                            UIViewAutoresizingFlexibleLeftMargin |
                            UIViewAutoresizingFlexibleBottomMargin |
                            UIViewAutoresizingFlexibleTopMargin;
}

为什么会发生这种行为?如何修复它,以便视图覆盖整个屏幕而没有任何额外的边距?

这是一张图片

我的视图是由 GUI 创建的,这是我的视图堆栈的图像,最后一个视图是 mainViewContainer

ios objective-c uikit
1个回答
-2
投票

好吧,这就是具有 mainViewController @HangarRash

的约束

© www.soinside.com 2019 - 2024. All rights reserved.