我正在视图控制器中创建一个项目。我有图像视图,标签和scrollview
。但是当我改变方向时,它的对齐方向不好吗?
有什么方法可以正确对齐吗?我的滚动视图也不工作。我在故事板中将委托设置为视图。我的控制框是(横屏模式)。
book_cover_image.frame=CGRectMake(50,20,250,300);
label_book_name.frame=CGRectMake(350,20,500,50);
label_book_author.frame=CGRectMake(350,76 , 500, 50);
label_book_price.frame=CGRectMake(350,135, 500, 50);
image_price_rupees.frame=CGRectMake(100, 330, 22, 16);
[buy_button setFrame:CGRectMake(13, 380, 119, 32)];
[preview_button setFrame:CGRectMake(150, 380, 113, 32)];
RecommendedBooksView.frame=CGRectMake(0,400,1024,368);
_thumbnailListView.frame=CGRectMake(15, 50, 950,350);
你可以考虑使用UIView的autoresizingMask属性在旋转过程中自动调整视图的大小和位置。
http://www.techpaa.com/2012/05/understanding-uiview-autoresizing.html如果autoresizingMask不能达到你想要的效果,你可以通过实现:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
[UIView animateWithDuration:duration animations:^{
//set new frame properties
}];
}