我是 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
是一个结构,而不是一个 Objective-C 类。那么,我可以将代码行重新定义为:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
上面的代码是否相同CGRect switchViewFrame = switchView.frame;
?