我是iOS应用程序开发的新手。
我正在关注一个教程,该教程在 BIDAppDelegate.m
中包含以下代码段- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.switchViewController = [[BIDSwitchViewController alloc]
initWithNibName:@"SwitchView" bundle:nil];
UIView *switchView = self.switchViewController.view;
/**** WHY here do not use pointer variable? ****/
CGRect switchViewFrame = switchView.frame;
switchViewFrame.origin.y+=[UIApplication sharedApplication].statusBarFrame.size.height;
switchView.frame = switchViewFrame;
self.window.rootViewController=self.switchViewController;
...
...
return YES;
}
我理解上面代码的作用,通常,当应用程序启动时,它会加载根控制器的视图(switchViewController
)&做一些观点调整。
我的问题是,在代码中为什么CGRect switchViewFrame = switchView.frame;
不会像这样使用指针变量:CGRect *switchViewFrame = switchView.frame;
?
===============更新==================
现在,我意识到原因是CGRect
是一个结构,而不是一个客观的c类。
那么,我可以重新定义代码行:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
以上代码是否与CGRect switchViewFrame = switchView.frame;
相同?
答案 0 :(得分:6)
CGRect
是C结构,而不是Objective-C对象。 CGRect
在CGGeometry.h
中声明,它是Core Graphics框架的一部分,它具有C API。