我正在制作一个应用程序,我在 objective-c 中制作自己的自定义键盘。
我指的是 this app
所以我想要像在 View 中滚动那样的图像。
我拍摄了一个 ScrollView 并将所有图像放入其中,它在纵向模式下工作正常,但对于横向模式,当我通过自动布局设置它时,滚动不起作用或 View 设置不正确。
所以请任何人都可以指导我。
使用带有自动布局的 Collection View 更好吗?
提前致谢。
最佳答案
Collection View 是比 ScrollView 更好的选择。使用 scrollview,您必须手动执行很多操作,而 collectionView 已经实现了。
ScrollView 和自动布局不太兼容:)
如果您仍然想使用 ScrollView ,则需要更新对方向更改的约束。
- (void)awakeFromNib {
[super awakeFromNib];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateIntrinsicConstraints) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)updateIntrinsicConstraints {
[self.widthConstraint setConstant:CGRectGetWidth(self.superview.frame)];
[self.heightConstraint setConstant:CGRectGetHeight(self.superview.frame))];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
在我的示例中,我假设您希望 scrollView 填充它的父 View 。如果不是这种情况,您将需要使用适合您的情况的适当值。
另一方面,使用 collectionView 时,您不必更改方向更改的约束,这是一个更简洁的解决方案。
如果您需要更多帮助,请告诉我
关于ios - 在纵向和横向中使用 objective-c 中的图像设置自定义键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29553417/