这是一些代码:
@interface VVVIEwController ()@property (weak,nonatomic) IBOutlet UIVIEw *pinnedControls;@property (nonatomic,strong) NSMutableArray *pinnedVIEws;@end@implementation VVVIEwController- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; self.pinnedVIEws = [NSMutableArray array]; [self.pinnedVIEws addobject:self.pinnedControls];}-(voID)vIEwWillLayoutSubvIEws{ [super vIEwWillLayoutSubvIEws]; [UIVIEwController rotatePinnedVIEws:self.pinnedVIEws forOrIEntation:self.interfaceOrIEntation];}- (voID)willAnimateRotationToInterfaceOrIEntation:(UIInterfaceOrIEntation)toInterfaceOrIEntation duration:(NSTimeInterval)duration{ [super willAnimateRotationToInterfaceOrIEntation:toInterfaceOrIEntation duration:duration]; if (UIInterfaceOrIEntationIsLandscape(toInterfaceOrIEntation) && UIInterfaceOrIEntationIsLandscape(self.interfaceOrIEntation)) { [UIVIEwController rotatePinnedVIEws:self.pinnedVIEws forOrIEntation:toInterfaceOrIEntation]; }}@end
我们在UIVIEwController上创建了一个类别来处理这种行为.这是相关的代码:
@implementation UIVIEwController (VVSupport)+ (voID)rotatePinnedVIEws:(NSArray *)vIEws forOrIEntation:(UIInterfaceOrIEntation)orIEntation { const CGAffinetransform t1 = [UIVIEwController pinnedVIEwTansformForOrIEntation:orIEntation counter:YES]; const CGAffinetransform t2 = [UIVIEwController pinnedVIEwTansformForOrIEntation:orIEntation counter:NO]; [vIEws enumerateObjectsUsingBlock:^(UIVIEw *vIEw,NSUInteger IDx,BOol *stop) { // Rotate the vIEw controller vIEw.transform = t1; [vIEw.subvIEws enumerateObjectsUsingBlock:^(UIVIEw *counterVIEw,BOol *stop) { // Counter-rotate the controlsUIin the vIEw controller counterVIEw.transform = t2; }]; }];}+ (CGAffinetransform)pinnedVIEwTansformForOrIEntation:(UIInterfaceOrIEntation)orIEntation counter:(BOol)counter { CGAffinetransform t; switch ( orIEntation ) { case UIInterfaceOrIEntationPortrait: case UIInterfaceOrIEntationPortraitUpsIDeDown: t = CGAffinetransformIDentity; break; case UIInterfaceOrIEntationLandscapeleft: t = CGAffinetransformMakeRotation(counter ? M_PI_2 : -M_PI_2); break; case UIInterfaceOrIEntationLandscapeRight: t = CGAffinetransformMakeRotation(counter ? -M_PI_2 : M_PI_2); break; } return t;}@end
这是笔尖的样子:
命名为nib的UIVIEw是pinnedControls的IBOutlet:
当我在iOS7或iOS8下以纵向模式运行时,我得到这个:
我在横向模式下看到iOS7下的预期结果:
但在iOS8(GM)下,我没有这种行为.这就是我所看到的:
请注意,带有“固定标签”文本的UILabel中心与固定UIVIEw的底部保持距离,UIVIEw的尺寸没有改变以适应旋转. UIVIEw的所有边缘都固定在超视图的顶部,左侧,底部和右侧.
在我看来,转换属性在iOS8下与auto Layout的交互方式不同.我在这里有点困惑.我知道我不能依赖这个框架.我可能只是开始手动设置边界,但这似乎是错误的事情,基本上是围绕自动布局结束.
解决方法 所以这让我疯狂了过去几天,我能够通过改变动画块中settransform调用的时间来解决这个问题.进入风景时,我正在设置转换后设置新帧.去画像时,我在设置新帧之前设置了变换.所有这些都发生在“animateWithDuration …”方法的动画块中
我不确定它是否会直接帮助您使用您的代码,但它可能会激发一些灵感来解决它,因为我们肯定有类似的问题
总结以上是内存溢出为你收集整理的autolayout – UIView在iOS8下使用CGAffineTransform旋转时不调整大小全部内容,希望文章能够帮你解决autolayout – UIView在iOS8下使用CGAffineTransform旋转时不调整大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)