0
我是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;
?
我可以重新定义一行代码:struct CGRect switchViewFrame,* sViewFrame; sViewFrame = switchView.frame;'? – Mellon
你为什么要做这样的事情? Objective-C是C的一个严格超集,你必须放心地混合C和Objective-C。 – PatrickNLT
您将不得不为sViewFrame分配内存(并释放它),并确保您复制数据内容,否则您必须将switchView.frame的地址分配给sViewFrame。但是,它不符合你的建议。你为什么想这么做?或者你只是出于好奇 - 这是可以理解的和学习的问题? –