繁体   English   中英

如何在ipad中将cgrect作为参数传递以及如何将cgrect作为返回类型

[英]how to pass cgrect as parameter and how to get cgrect as a return type in ipad

大家好,我要问一个基本问题,我在很多链接中搜索了我的问题,但是没有一个没有给出确切的结果。这是我的问题:

我想传递rect值并使用某种转换返回相同的类型,因为我写了一个方法,但是它给了我我知道这可能是语法错误的错误,请更正以下代码

-(void)viewDidLoad{
    CGRect testRect=getNewRect(self.view.frame);
}

我自己的方法在这里

CGRect getNewRect(CGRect normalRect){
    //some transformation
    return tranfermedrect;
}

提前给我您的建议谢谢..

使用下面的行可以解决您的问题。

[self yourFunction:[NSValue valueWithCGRect:rectFrame]];

上面的行是简单的方法调用,在Objective-C中,您不能将CGRect作为参数发送。 因此,您必须将CGRect转换为NSValue。

在被调用的函数中,您从NSValue获得了GGRect

yourView.frame = [rect CGRectValue];

希望对您有帮助。

请尝试以下

-(void)viewDidLoad{
    CGRect testRect= [self getNewRect:self.view.frame];
}

-(CGRect) getNewRect:(CGRect) normalRect{

    //some transformation
    return tranfermedrect;
}

在.h文件中添加以下内容

  -(CGRect) getNewRect:(CGRect) normalRect ;
-(void)viewDidLoad{
    CGRect testRect= [self getNewRect:self.view.frame];
    NSLog(@"New rect %@",NSStringFromCGRect(testRect));
}

-(CGRect) getNewRect:(CGRect) normalRect{

    //some transformation
    return tranformedRect;
}

看看这是否有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM