如何更改视图的比例 [英] how to change the scale of view
问题描述
我正在尝试制作类似于应用程序 Euro Sport 中的侧边栏菜单!当菜单从左滑动时,sourceviewcontroller
向左滑动并变小.
I am trying to make sidebar menu like in app Euro Sport! When the menu slides from left , the sourceviewcontroller
slide to left and becomes smaller.
var percentWidthOfContainer = containerView.frame.width * 0.2 // this is 20 percent of width
var widthOfMenu = containerView.frame.width - percentWidthOfContainer
bottomView.transform = self.offStage(widthOfMenu)
bottomView.frame.origin.y = 60
bottomView.frame.size = CGSizeMake(widthOfMenu, 400)
bottomView.updateConstraints()
menucontroller.view.frame.size = CGSizeMake(widthOfMenu, containerView.frame.height)
menucontroller.updateViewConstraints()
这里,底部视图是sourceviewcontroller.view.所以,问题是如何缩放底部视图.就我而言,我可以更改大小,但视图中的所有内容仍保持相同大小.
Here, the bottom view is sourceviewcontroller.view. So, the question is how to scale bottom view. In my case , i can change the size but everything inside view is still in the same size.
推荐答案
您可以使用 CGAffineTransformScale
来缩放 UIView
的实例
You can use CGAffineTransformScale
to scale instance of UIView
例如
假设你有一个 UIView
的实例
Suppose you have an instance of UIView
as
UIView *view;
//假设您已经实例化并自定义了您的视图
// lets say you have instantiated and customized your view
....
//将视图的原始变换保留在变量中
// Keep the original transform of the view in a variable as
CGAffineTransform viewsOriginalTransform = view.transform;
//缩小视图使用 CGAffineTransformScale
view.transform = CGAffineTransformScale(viewsOriginalTransform, 0.5, 0.5);
//再次放大视图
view.transform = CGAffineTransformScale(viewsOriginalTransform, 1.0, 1.0);
这篇关于如何更改视图的比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!