【发布时间】:2013-04-17 08:14:53
【问题描述】:
我是 iOS 应用开发的新手。
我正在关注一个教程,该教程在 BIDAppDelegate.m
中有以下代码 sn-p- (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 是一个结构,而不是一个objective-c 类。
那么,我可以将代码行重新定义为:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
上面的代码和CGRect switchViewFrame = switchView.frame;一样吗?
【问题讨论】:
标签: ios objective-c cocoa-touch ios5 ios6