Mel*_*lon 0 cocoa-touch objective-c ios ios5 ios6
我是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;
}
Run Code Online (Sandbox Code Playgroud)
我理解上面的代码做了什么,通常,当应用程序启动时,它会加载根控制器的视图(switchViewController
)并进行一些视图调整.
我的问题是,在代码中为什么CGRect switchViewFrame = switchView.frame;
不像这样使用指针变量:CGRect *switchViewFrame = switchView.frame;
?
===============更新==================
现在,我意识到原因是CGRect
结构,而不是客观的c类.那么,我可以重新定义代码行:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
Run Code Online (Sandbox Code Playgroud)
以上代码是否相同CGRect switchViewFrame = switchView.frame;
?
CGRect
是C结构,而不是Objective-C对象.CGRect
声明CGGeometry.h
,它是Core Graphics框架的一部分,它具有C API.