Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIView子视图中的原点_Iphone_Objective C_Uiview - Fatal编程技术网

Iphone UIView子视图中的原点

Iphone UIView子视图中的原点,iphone,objective-c,uiview,Iphone,Objective C,Uiview,我遇到了一个让我发疯的问题。。。我知道这一定是一个简单的修复,但我在网上找不到任何东西(但是!可能找错了地方) 我在视图中放置了一组带有循环的按钮: //make the button smaller and position CGRect buttonFrame = button.frame; buttonFrame.size = CGSizeMake(41, 41); buttonFrame.origin = CGPointMake(10+(4

我遇到了一个让我发疯的问题。。。我知道这一定是一个简单的修复,但我在网上找不到任何东西(但是!可能找错了地方)

我在视图中放置了一组带有循环的按钮:

//make the button smaller and position
        CGRect buttonFrame = button.frame;
        buttonFrame.size = CGSizeMake(41, 41);
        buttonFrame.origin = CGPointMake(10+(43*i), 415);
        button.frame = buttonFrame;
这很有效…但现在我想把它们添加到另一个视图中,它们就消失了。有问题的代码行是:

buttonFrame.origin = CGPointMake(10+(43*i), 415);
我相信这一定是基于self.view的坐标,而不是包含按钮的新子视图。超级视图是否需要新的CGContext

我试过这样的方法:

 buttonFrame.origin = [newView CGPointMake(10+(43*i), 415)];
但这导致了各种各样的错误


谢谢你的时间

buttonFrame.origin=[newView CGPointMake(10+(43*i),415)];-这行代码没有意义,因为CGPointMake是C函数,而不是ObjectiveC方法,所以不能像消息一样将其发布到object。
如果要添加子视图,必须使用[newView addSuview:button];并确保已将视图添加到另一个视图。

指定为视图帧的CGRect的原点是视图将放置在其superview的偏移位置

因此,如果使用(100、100、200、200)的CGRect,则视图在原点右侧为100像素,在南部为100像素(还请记住,iOS视图坐标系原点位于左上角),其大小为200x200


您的按钮将比其superview的本地原点(左上角)低415像素,这可能会使其无法查看。

非常感谢,这是显而易见的。我需要更多的睡眠。此外,考虑使用一些其他的核心图形方便功能,如<代码> CGReCurTySt/Obj>,返回一个新的<代码> CGRECT < /代码>,比您提供的数量小(或更大),并且<代码> CGRelpOuts< /C>它返回一个新的
CGRect
,该值从提供的
CGRect
中偏移给定的量。它们与您所展示的代码没有本质上的区别,但通常有助于提高清晰度(特别是在caffiene不多的时候)。