我是 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;
}
我明白上面的代码做了什么,一般来说,当应用程序启动时,它会加载根 Controller (switchViewController
)的 View 并进行一些 View 调整。
我的问题是,在代码中,为什么 CGRect switchViewFrame = switchView.frame;
没有像这样使用指针变量:CGRect *switchViewFrame = switchView.frame;
?
===============更新==================
现在,我意识到原因是 CGRect
是一个结构,而不是一个 objective-c 类。
那么,我能否将这行代码重新定义为:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
上面的代码是否与 CGRect switchViewFrame = switchView.frame;
相同?
最佳答案
CGRect
是一个 C 结构,而不是一个 Objective-C 对象。 CGRect
在 CGGeometry.h
中声明,它是具有 C API 的 Core Graphics 框架的一部分。
关于ios - 为什么不用指针变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16054933/