我在我的应用程序中发现了一个奇怪的行为,其中一个连接器IBOutlet
在我的视图控制器viewWillAppear:
和之间的调用之间有连接视图的框架viewDidAppear:
.这是我的UIViewController
子类中的相关代码:
-(void)viewWillAppear:(BOOL)animated {
NSLog(@"%@", self.scrollView);
}
-(void)viewDidAppear:(BOOL)animated {
NSLog(@"%@", self.scrollView);
}
Run Code Online (Sandbox Code Playgroud)
和结果日志输出:
MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>
MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 44; 320 416); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>
Run Code Online (Sandbox Code Playgroud)
这清楚地表明帧在两次调用之间发生变化.我想在viewDidLoad
方法中使用视图进行设置,但是如果内容无法在屏幕上显示,我就无法更改内容,这似乎毫无用处.可能会发生什么?
不久之前,我发布了一个关于在视图的两个角上进行四舍五入的问题,得到了很好的响应,但是在实现它时遇到了问题.这是我的drawRect:方法:
- (void)drawRect:(CGRect)rect {
//[super drawRect:rect]; <------Should I uncomment this?
int radius = 5;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, radius, M_PI, M_PI / 2, 1);
CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
CGContextClosePath(context);
CGContextClip(context);
}
Run Code Online (Sandbox Code Playgroud)
正在调用该方法,但似乎不会影响视图的结果.有什么想法吗?
两者有什么区别?如果我正在写一个程序,我什么时候需要这个:
void aFunction() {
//do something
}
Run Code Online (Sandbox Code Playgroud)
我什么时候需要这个:
-(void)aMethod {
//do something else
}
Run Code Online (Sandbox Code Playgroud) 在我的iPad应用程序中,当用户单击按钮时,我希望第二个视图显示在主视图中.新视图将小于第一个视图,并在显示时使背景变暗.我希望新视图的前两个角显示为圆角,但使用cornerRadius将所有圆角设置为圆角.我怎样才能使两个圆角变圆?
我最近决定尝试学习如何编写程序集.拥有2011年型号的MBP,我无法找到有关如何在我的计算机上编写和执行汇编代码的更多信息.如果有人能指出我在这方面的正确方向(以及提供任何有用的教程),将不胜感激.
是否有相当于NSString的sizeWithFont:
方法,可用于计算给定宽度的UITectView中文本的高度?NSString的所有方法只能在我能说的单行上运行.
我一直在使用Objective-C一段时间,但从来没有真正理解所有字符串之前@符号的用途是什么.例如,为什么必须声明这样的字符串:
NSString *string = @"This is a string";
Run Code Online (Sandbox Code Playgroud)
而不是这样的:
NSString *anotherString = "This is another string";
Run Code Online (Sandbox Code Playgroud)
就像你用Java或许多其他编程语言一样.有充分的理由吗?
我正在编写一个使用NSURLConnection来使用异步Web请求的应用程序,因此我运行了多个线程.为了确保我的应用程序的主要逻辑发生在一个线程上,我正在大量使用performSelectorOnMainThread:waitUntilDone:
.有时虽然,我在主线程上运行它,这激起了我的好奇心.
如果performSelectorOnMainThread:waitUntilDone:
在主线程中调用?它的行为和它一样performSelector:
吗?如果waitUntilDone:
是的话YES
?怎么样NO
?
编辑:我发现,当waitUntilDone:
是YES
时,执行选择(几乎)立即,但我不能当如果执行弄清楚waitUntilDone:
是NO
.
我试图在用Swift编写的Xcode项目中使用LLVM C API.为此,我在这里松散地遵循指南,但遇到了麻烦.在编译步骤中,在Xcode中添加包含路径到构建设置后,我收到以下错误:
<unknown>:0: error: module 'LLVM_Backend.CodeGen.PBQP.math' requires feature 'cplusplus'
/Users/freddy/Development/llvm-source/build/include/llvm/Support/DataTypes.h:35:10: note: submodule of top-level module 'LLVM_Backend' implicitly imported here
#include <math.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "./Analysis.h"
^
/Users/freddy/Development/llvm-source/llvm/include/llvm-c/./Analysis.h:22:10: note: in file included from /Users/freddy/Development/llvm-source/llvm/include/llvm-c/./Analysis.h:22:
#include "llvm-c/Types.h"
^
/Users/freddy/Development/llvm-source/llvm/include/llvm-c/Types.h:17:10: error: could not build module 'LLVM_Support_DataTypes'
#include "llvm/Support/DataTypes.h"
^
/Users/freddy/Development/Xcode Projects/SwiftLLVMTest/SwiftLLVMTest/main.swift:10:8: error: could not build Objective-C module 'LLVM_C'
import LLVM_C
Run Code Online (Sandbox Code Playgroud)
幻灯片的下一步是添加标志:
-Xcc -D__STDC_CONSTANT_MACROS \
-Xcc -D__STDC_LIMIT_MACROS
Run Code Online (Sandbox Code Playgroud)
但我不确定在构建设置中将它们放在哪里 - 将它们添加到'其他C标志'或'其他Swift标志'选项似乎没有做任何事情.
我应该怎么做呢?
在WWDC 2019上,Apple宣布了一种新的“卡片式”外观模态演示,并带有内置手势,可通过向下滑动卡片来消除模式视图控制器。他们还引入了新isModalInPresentation
属性,UIViewController
以便您可以选择拒绝这种解雇行为。
但是到目前为止,我还没有找到在SwiftUI中模拟这种行为的方法。使用.presentation(_ modal: Modal?)
,不,据我所知,让你以同样的方式禁止解雇手势。我还尝试将模式视图控制器放在内UIViewControllerRepresentable
View
,但这似乎也无济于事:
struct MyViewControllerView: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<MyViewControllerView>) -> UIHostingController<MyView> {
return UIHostingController(rootView: MyView())
}
func updateUIViewController(_ uiViewController: UIHostingController<MyView>, context: UIViewControllerRepresentableContext<MyViewControllerView>) {
uiViewController.isModalInPresentation = true
}
}
Run Code Online (Sandbox Code Playgroud)
即使在出席会议之后,.presentation(Modal(MyViewControllerView()))
我仍然可以向下滑动以消除视图。当前是否可以使用现有的SwiftUI构造来做到这一点?