当我导航到我的一个xib文件时,Xcode将文件标记为触摸.撤消和还原无效.保存似乎没有坏处,但是故障导致我经常额外的git工作.
有没有其他人看到这个或对我的MainWindow.xib中的某些东西有所了解会导致它?
2016年编辑 - 仍在发生!
我是块的忠实粉丝,但没有将它们用于并发.经过一些谷歌搜索,我拼凑了这个想法,以隐藏我在一个地方学到的一切.目标是在后台执行一个块,当它完成时,执行另一个块(如UIView动画)......
- (NSOperation *)executeBlock:(void (^)(void))block completion:(void (^)(BOOL finished))completion {
NSOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:block];
NSOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
completion(blockOperation.isFinished);
}];
[completionOperation addDependency:blockOperation];
[[NSOperationQueue mainQueue] addOperation:completionOperation];
NSOperationQueue *backgroundOperationQueue = [[NSOperationQueue alloc] init];
[backgroundOperationQueue addOperation:blockOperation];
return blockOperation;
}
- (void)testIt {
NSMutableString *string = [NSMutableString stringWithString:@"tea"];
NSString *otherString = @"for";
NSOperation *operation = [self executeBlock:^{
NSString *yetAnother = @"two";
[string appendFormat:@" %@ %@", otherString, yetAnother];
} completion:^(BOOL finished) {
// this logs "tea for two"
NSLog(@"%@", string);
}];
NSLog(@"keep this operation …Run Code Online (Sandbox Code Playgroud) objective-c nsoperation nsoperationqueue ios nsblockoperation
Apple文档似乎表明,在将视频录制到文件时,应用程序可以动态更改URL,没有任何问题.但我看到了一个问题.当我尝试这个时,录制代表被调用错误...
这项行动无法完成.(OSStatus错误-12780.)信息字典是:{AVErrorRecordingSuccessfullyFinishedKey = 0; }
("can not"中的时髦单引号来自日志记录[error localizedDescription])
这是代码,基本上是对WWDC10 AVCam示例的调整:
1)开始录音.每隔几秒钟启动计时器以更改输出URL
- (void) startRecording
{
// start the chunk timer
self.chunkTimer = [NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(chunkTimerFired:)
userInfo:nil
repeats:YES];
AVCaptureConnection *videoConnection = [AVCamCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
if ([videoConnection isVideoOrientationSupported]) {
[videoConnection setVideoOrientation:[self orientation]];
}
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]];
}
NSURL *fileUrl = [[ChunkManager sharedInstance] nextURL];
NSLog(@"now recording to %@", [fileUrl absoluteString]);
[[self movieFileOutput] startRecordingToOutputFileURL:fileUrl recordingDelegate:self];
}
Run Code Online (Sandbox Code Playgroud)
2)当计时器触发时,更改输出文件名而不停止记录
- (void)chunkTimerFired:(NSTimer *)aTimer {
if ([[UIDevice currentDevice] …Run Code Online (Sandbox Code Playgroud) 有人可以帮我缩短以下方法吗?我从这开始,我很喜欢这个:
def self.some_hash
{ "foo" => "bar" }
end
Run Code Online (Sandbox Code Playgroud)
现在我想添加一个可选键.我能想到的最简洁的语法是这样的:
def self.some_hash(some_key=nil)
answer = { "foo" => "bar" }
answer[some_key] = "yucky, long-winded syntax" if some_key
answer
end
Run Code Online (Sandbox Code Playgroud)
修改后的方法有效,但我对虚拟墨水的浪费感到不满意.有没有办法缩短它?我意识到可以在哈希文字上使用三元运算符,但这会强制(我认为)"foo" => "bar"在条件的每个分支上重复该对,这也略微小于原始状态.
我在我的iOS应用程序中使用UIGestureRecognizer,我遇到了一些问题.
我只希望手势在视图的某个区域中工作,所以我创建了一个具有特定帧的新UIView并将其添加到根视图中.这个手势很好用,但现在唯一的问题是我无法点击新视图下面/后面的东西(根视图上的对象).如果我将userInteractionEnabled设置为NO,则会中断手势,因此这不是一个选项.
我该怎么做才能解决这个问题?
谢谢.
在一个通用项目中尝试我,我想从故事板中加载一个vc标识符.有没有办法避免在访问故事板时明确检查成语.
这个丑陋的代码有效....
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
}
else {
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
}
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
Run Code Online (Sandbox Code Playgroud)
但是你好.字符串文字主要故事板很难看(不知道为什么项目不能保存主故事板设置,以便应用程序可以说[UIStoryboard mainStoryboard];)但显式的成语检查是一个过头的桥梁.
是否有任何隐藏的智能(可与支持视网膜显示的"@ 2x"图像后缀相比)清除此代码?
有没有办法更简洁地指定这样的许多验证?
validates :col_a, :presence => {:message => 'col_a cannot be blank'}
validates :col_b, :presence => {:message => 'col_b cannot be blank'}
validates :col_c, :presence => {:message => 'col_c cannot be blank'}
Run Code Online (Sandbox Code Playgroud)
如果必须的话,我会满足于通用信息.
我希望我的子视图是一个16:9的矩形,位于其超视图的顶部.换句话说,我希望它:
这个代码几乎可以做到,除了我很难使水平约束工作而不是过度或受限制......
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor redColor];
[self.view addSubview:contentView];
contentView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = NSDictionaryOfVariableBindings(contentView);
NSMutableArray *constraints = [NSMutableArray array];
// this layout string is more like 'wishful coding'. I don't see why it wouldn't work
// but clearly this one is the problem
[constraints addObjectsFromArray:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-(>=0)-[contentView(<=400)-(>=0)-]"
options:0 metrics:0 views:views]];
// this centering constraint below almost …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户可以使用电子邮件/密码验证/登录我的后端.现在我正在考虑实现触摸ID.
但我对使用触摸ID的登录流程感到困惑.
使用下面的代码,我可以轻松验证用户:
func authenticateUser() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
[unowned self] success, authenticationError in
DispatchQueue.main.async {
if success {
self.runSecretCode()
} else {
let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
self.present(ac, animated: true)
}
}
}
} else {
let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch …Run Code Online (Sandbox Code Playgroud) 我正在使用我在这里下载的 jsSHA 1.3.1,并在我的localhost上用于学习项目.它的结果与我通过引用遥控器获得的副本略有不同,如下所示:
<script src="https://raw.github.com/Caligatio/jsSHA/master/src/sha1.js"></script>
Run Code Online (Sandbox Code Playgroud)
由于@Andreas 在这里的出色答案,远程拷贝对我来说效果很好.
但它给我留下了一个新问题:包含副本与引用远程js库的理由是什么?它是否像'销售'库一样,使我的应用程序与代码中的后续更改隔离开来?
ios ×6
iphone ×5
objective-c ×2
autolayout ×1
avcam ×1
avfoundation ×1
hashtable ×1
ipad ×1
javascript ×1
nsoperation ×1
ruby ×1
sha ×1
storyboard ×1
swift ×1
touch-id ×1
uiview ×1
validation ×1
xcode ×1
xib ×1