iOS:旋转的 UITextField 内不显示文本
我已经使用 Interface Builder 创建了一个 UITextField。在 viewDidLoad 中,我旋转文本字段以匹配我们需要的横向视图:
name.transform = CGAffineTransformMakeRotation(-(M_PI/2));
不幸的是,这不会带来文本。文本位于文本字段外部、背景后面,如下所示。
根据 StackOverflow 上的其他问题,我尝试过:
name.textAlignment = UITextAlignmentLeft;
name.textAlignment = UITextAlignmentRight;
并且这个附加功能:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
name.textAlignment = UITextAlignmentLeft;
name.textAlignment = UITextAlignmentRight;
}
两者都不是解决方案有效。
-----更新-----
我能够将笔尖定向为横向而不是纵向,这解决了问题。然而,这似乎是一个错误。我假设旋转的 UITextField 应该带有文本。
I have created a UITextField with Interface Builder. In viewDidLoad
, I rotate the text field to match the landscape view we need:
name.transform = CGAffineTransformMakeRotation(-(M_PI/2));
Unfortunately, this does not bring the text with it. The text sits outside of the textfield, behind the background, as seen below.
Based on other questions here at StackOverflow, I have tried:
name.textAlignment = UITextAlignmentLeft;
name.textAlignment = UITextAlignmentRight;
and this additional function:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
name.textAlignment = UITextAlignmentLeft;
name.textAlignment = UITextAlignmentRight;
}
Neither solution works.
-----UPDATE-----
I was able to just orient the nib for landscape rather than portrait, and that solved the problem. However, this seems like a bug. I'd assume a rotated UITextField should bring the text with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要手动旋转文本字段?只需让你的 UIViewController 执行其正常的旋转行为(这会转换视图控制器的主视图),所有子视图都将在横向中可用。
Why are you rotating the text field manually? Just let your UIViewController do its normal rotation behaviour (which transforms the view controller's main view) and all the subviews will be usable in landscape.