objective-c - Objective C 如果成功就简单

标签 objective-c ios uikit

大家好,应用“如果成功”方法的最佳方法是什么? 我正在尝试这个,但没有运气。

BOOL success = false;

success = [self.view addSubview:carregandoView];
carregandoView.backgroundColor = [UIColor clearColor];
carregandoView.center = self.view.center;

if (!success)
{

 //stuff
}

感谢您的回复!

最佳答案

首先,addSubview: 不会返回任何内容。其次,您可以测试 subview 是否已添加,如下所示:

if (carregandoView.superview != self.view)
    // do something

第三,您只能将 View 添加到 super View 一次(也就是说,多次发送 [self.view addSubview: carregandoView] 除了将 subview 置于前面之外不会执行任何操作),您可以使用此技巧来确保 subview 保持在其同级 View 之上。

关于objective-c - Objective C 如果成功就简单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4831920/

相关文章:

objective-c - 将 Plist (NSString) 解析为 NSDictionary

ios - 当超过 2 列时,条形图会向上跳跃

ios - 使用 Xcode 在 iOS 上实现多点连接

ios - 将字典对象附加到 UITableViewCell

ios - 用 UIGraphicsImageRenderer 的 jpegData 替换 UIImageJPEGRepresentation

ios - "NSString stringWithFormat:"和 "%zd"在 32 位设备中的奇怪行为

html - UIWebView 获取 HTML 源

iphone - dismissModalViewControllerAnimated使我的应用程序崩溃:(

ios - 如何在 iphone 上制作闪烁(或闪烁)的光标?

ios - Sprite Kit 艺术 Assets 命名约定