小编kpo*_*wer的帖子

GLKit的-drawRect:在屏幕旋转期间不调用

我有一个GLKit基于应用程序,显示一些简单的对象.

一切正常,除了屏幕旋转,在此期间GLKView不更新(-drawRect:未调用).因此,在旋转期间,投影矩阵不会根据动态变化的屏幕尺寸进行更新,并且对象看起来很糟糕(拉伸).

screen-rotation ios auto-rotation glkit glkview

5
推荐指数
2
解决办法
1518
查看次数

从后台线程播放OpenAL声音

在我的iOS应用程序中,我不想使用OpenAL播放声音.我有AudioManager类,负责声音管理(单例).创建所有声源和缓冲区(在第一次instance调用时).

因此,播放我需要的声音 - 是停止先前的声音,清除旧的缓冲区(必要的源),连接新的缓冲区,设置音高和增益,最后播放声音.所有这些操作都在playSound:(AMSound)sound方法中(AMSound是一个简单的枚举).

对于UI效果,我从主线程调用此方法.但我的应用程序有很多背景工作,有时还伴有声音效果.

我可以playSound:直接从后台线程调用,还是应该只在主线程上调用它?那么同步声音呢:一个是从主线程创建的,另一个是从背景创建的?

audio multithreading openal ios

4
推荐指数
1
解决办法
2807
查看次数

NSInvocationOperation和主线程

想象一下,我有一个视图,其中有一些UIKit对象作为其子视图(例如,UIActivityIndicatorView- 这无关紧要).此视图还有一个名为的选择器,doSomething它以某种方式管理UIKit对象(在我们的示例中,它可以启动或停止指示器视图).

我创建NSInvocationOperation(从视图的代码部分)initWithTarget:self selector:@selector(doSomething) object:nil.然后将其添加到NSOperationQueue.一切正常.

怎么样?!它应该是一个新的线程和非线程安全的UIKit对象!为什么没有发现错误(没有发生崩溃)?

iphone objective-c thread-safety nsoperationqueue

2
推荐指数
1
解决办法
3698
查看次数

使用NSInvocation在主线程上执行选择器

我想在主线程上执行动画(导致UIKit对象不是线程安全的),但是在一些单独的线程中准备它.我有(baAnimation - 之前已经分配了CABasicAnimation):

SEL animationSelector = @selector(addAnimation:forKey:);
NSString *keyString = @"someViewAnimation";

NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[workView.layer methodSignatureForSelector:animationSelector]];
[inv setTarget:workView.layer];
[inv setSelector:animationSelector];
[inv setArgument:baAnimation atIndex:2];
[inv setArgument:keyString atIndex:3];
[inv performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)

我明白了:

*** + [NSCFString length]:无法识别的选择器发送到类0x1fb36a0

呼叫:

>     #0 0x020984e6 in objc_exception_throw
>     #1 0x01f7e8fb in +[NSObject doesNotRecognizeSelector:]
>     #2 0x01f15676 in ___forwarding___
>     #3 0x01ef16c2 in __forwarding_prep_0___
>     #4 0x01bb3c21 in -[CALayer addAnimation:forKey:]
>     #5 0x01ef172d in __invoking___
>     #6 0x01ef1618 in -[NSInvocation invoke]
Run Code Online (Sandbox Code Playgroud)

[workView.layer addAnimation:baAnimation forKey:@"someViewAnimation"];工作正常.我究竟做错了什么?

iphone animation objective-c nsinvocation

2
推荐指数
1
解决办法
4550
查看次数

从UITableView中取出可重用的单元格

为什么这段代码工作正常:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.text = [NSString stringWithFormat:@"cell%i%i", indexPath.section, indexPath.row];
    }    
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

据我所知,单元标识符,只有当我移出cell.textLabel.text = ...if语句时,此代码才能正常工作.换句话说,为什么标签有正确的文本?

iphone objective-c deque uitableview

2
推荐指数
1
解决办法
8796
查看次数