ios 我如何使用 cgsize 制作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23307059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:00:51  来源:igfitidea点击:

How do I use cgsize make?

ioscgsize

提问by jwhyyou

I have been trying to use cgsizemakeas follows:

我一直在尝试使用cgsizemake如下:

I'm trying to make the frame of my image a different size using cgrectmakeinstead of changing the coordinates.

我正在尝试使用cgrectmake而不是更改坐标使我的图像的框架具有不同的大小。

So far I have tried

到目前为止我已经尝试过

 maincharacter.frame = cgsizemake (14, 14); 

but I keep getting the error

但我不断收到错误

assigning to cgrect from incompatible type CGsize

从不兼容的类型 CGsize 分配给 cgrect

回答by rmaddy

One solution would be:

一种解决方案是:

CGRect frame = maincharacter.frame;
frame.size = CGSizeMake(14, 14);
maincharacter.frame = frame;

回答by Mayank Jain

CGSize only accepts height and width

CGSize 只接受高度和宽度

CGSize c=CGSizeMake(width, height);

If you want to set the frame size use CGRectMake

如果要设置框架大小,请使用 CGRectMake

maincharacter.frame=CGRectMake(x-origin,y-origin, width, height);

回答by user2239950

maincharacter.frame must return (x, y, width, height) 4 parameters and CGSizeMake only have "width" and "height" 2 parameters. So You got an error. The solution is use frame.size, which returns 2 parameters to work with CGSizeMake(14, 14).

maincharacter.frame 必须返回(x, y, width, height) 4个参数,CGSizeMake只有“width”和“height”2个参数。所以你有一个错误。解决方案是使用 frame.size,它返回 2 个参数来处理 CGSizeMake(14, 14)。

回答by Hardik Vyas

 CGSize viewwidth;
    viewwidth=[[UIScreen mainScreen] bounds].size;

this will help you to get device current resolution using cgsize.

这将帮助您使用 cgsize 获取设备当前分辨率。

viewwidth.width or viewwidth.height

as above u can use it. and also as below code

如上所述,您可以使用它。以及如下代码

rightslide=[[UIView alloc]initWithFrame:CGRectMake(0,0, viewwidth.width, viewwidth.height)];

回答by LuAndre

below is an example of using CGSizeMake in a UIScrollView

下面是在 UIScrollView 中使用 CGSizeMake 的示例

var mainScrollView: UIScrollView?
var numPages = 3

override func viewDidLoad() {
    super.viewDidLoad()

    //this gets the screen frames size
    var fm: CGRect = UIScreen.mainScreen().bounds

    //creates a UIScrollView programmatically
    self.mainScrollView = UIScrollView(frame:CGRectMake(0, 0, fm.size.width, fm.size.height))

    self.mainScrollView!.contentSize = CGSizeMake(self.mainScrollView!.frame.size.width, self.mainScrollView!.frame.size.height * CGFloat(numPages))
 }

回答by nocarrier

To use the variable cwhich is of type CGSizeyou would call c.0and c.1for the height and width respectively. I don't know why they named those properties 0 and 1 but you will have to take that up with Dennis Ritchie

要使用c类型的变量,CGSize您将分别调用c.0c.1用于高度和宽度。我不知道他们为什么将这些属性命名为 0 和 1,但您必须与丹尼斯·里奇(Dennis Ritchie)一起接受

Here is an example usage of CGSizeMake:

这是一个示例用法CGSizeMake

        var makeSize =  CGSizeMake(size.0, size.1)
        let circ = SKShapeNode(ellipseOfSize: makeSize)

Hope that helps.

希望有帮助。