【发布时间】:2016-06-15 21:09:56
【问题描述】:
我在 iPhone 上有这 10 个键盘,它的屏幕与 iPhone 解锁屏幕基本相同,只是我的旋转调整按钮大小以适应屏幕。问题是旋转设备的动画会扭曲圆形,因为它们已经改变了大小,但cornerRadius在完成动画之前是相同的。旋转动画完成后,按钮会再次设置半径,从而使它们变为圆形。我不知道如何让 UIButtons 总是圆的,特别是在旋转动画期间。这基本上是我所拥有的:
- (void)viewDidLayoutSubviews {
[self setupButtons];
}
- (void)setupButtons {
for (UIButton *button in self.touchPadButtons) {
[self roundifyButton:button withRadius:radius];
}
}
- (void)roundifyButton:(UIButton *)button {
NSInteger height = button.frame.size.height;
radius = height/2;
button.layer.cornerRadius = radius;
button.layer.borderWidth = .6f;
button.layer.borderColor = [UIColor whiteColor].CGColor;
button.clipsToBounds = YES;
}
我尝试过使用:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
但似乎为了设置半径以通过该方法工作,我必须以编程方式设置按钮的大小,而不是使用自动布局。有人对处理这个有什么神奇的建议吗?我肯定不想像 Apple 那样轮换,但不幸的是,这个决定不是我的。
【问题讨论】:
标签: ios objective-c iphone uibutton autolayout