Tag: iphone

第一次播放声音时,AVAudioPlayer启动缓慢

我试图通过iPhone上的AVAudioPlayer播放(非常短 – less于2秒)的audio文件来消除启动延迟。 首先,代码: NSString *audioFile = [NSString stringWithFormat:@"%@/%@.caf", [[NSBundle mainBundle] resourcePath], @"audiofile"]; NSData *audioData = [NSData dataWithContentsOfMappedFile:audioFile]; NSError *err; AVAudioPlayer *audioPlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithData:audioData error:&err]; audioPlayer.delegate = self; [audioPlayer play]; 一旦完成,我还实现了audioPlayerDidFinishPlaying方法来释放AVAudioPlayer。 我第一次播放audio时,延迟是可以触摸的 – 至less2秒。 然而,之后,声音立即播放。 我怀疑罪魁祸首是最初从闪存中读取很长一段时间的[NSData dataWithContentsOfMappedFile],但后来读取的速度很快。 不过,我不确定如何testing。 是这样吗? 如果是的话,我应该只是预先caching的NSData对象,积极清理它们在低内存条件?

ApplicationWillTerminate在iOS 4.0中

applicationWillTerminate委托方法没有在iOS 4.0中调用当我点击主页button,我看到applicationWillResignActive和applicationDidEnterBackground委托方法被调用。 – (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"Application Did Resign Active"); } – (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"Application Did Enter Background"); } 当我双击主页button,再次启动应用程序,我发现applicationWillEnterForeground和applicationDidBecomeActive委托方法被调用。 – (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"Application Will Enter Foreground"); } – (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"Application Did Become Active"); } 但是我想知道什么时候会调用applicationWillTerminate委托方法,在哪里做一些DB /文件备份例程。 – (void)applicationWillTerminate:(UIApplication *)application{ } 我甚至试图打减号,并删除在后台运行的应用程序,但它仍然没有调用任何委托方法。 有任何想法吗 ???

你如何改变UIFont的颜色?

我search了网页,但是我不能得到一个好的答案,虽然我确信这很简单。 有人可以告诉我如何做到以下几点:制作名为“Helvetica-Bold”,大小为8.0,颜色为黑色的UIFont。 我有名字和大小,但我不知道如何改变颜色: UIFont *textFont = [UIFont fontWithName:@"Helvetica-Bold" size:8.0]; 谢谢!

UITableViewCell中的UIButton

我有一个UITableViewCell里面的图像的UIButton。 当单元格被加亮时,不pipe用户是否在button的边界内点击,button也都进入高亮状态(即,图像的较暗的阴影)。 我不想要这个function – 我只希望点击button时突出显示button,而不是点击整个单元格。 我试图设置图像突出显示的状态是一样的正常图像。 这解决了这个问题,但是当它真的被突出显示时,它停止了改变颜色的button。 任何想法如何达到预期的效果?

在iOS 7中移动状态栏

我面临的问题是这样的: 我想实现一个好的devise和左/右菜单的iOS 7应用程序,它出现在主视图animation自己的右/左后。 我正在用[UIView animateWithDuration…]代码来做这[UIView animateWithDuration…] ,但这并不重要。 我想达到的效果与Mailbox iOS 7应用程序具有的效果相同:使用主视图移动状态栏(向右/向左) 图像更好的解释: 我只find这篇关于这个问题的文章,其中一些工作代码使用私有API,我不想使用,因为我希望我的应用在App Store上被接受。 我想达到同样的效果(“合法”)。 有谁知道如何? 谢谢!

如何以编程方式创buildUIScrollView?

好的,所以这里的关键是我没有使用IB,因为我正在使用的视图是以编程方式创build的。 UIView覆盖屏幕的下半部分,并在其上有一堆button。 但是,我想添加更多的button到UIView ,而不是更大。 为此,我想在视图中创build一个UIScrollView ,这将允许我在屏幕上添加更多button,以便用户可以滚动到它们。 我认为这是如何工作的。 self.manaView = [[[UIView alloc] initWithFrame:frame] autorelease]; self.manaView.backgroundColor = [UIColor purpleColor]; UIScrollView *scroll = [UIScrollView alloc]; scroll.contentSize = CGSizeMake(320, 400); scroll.showsHorizontalScrollIndicator = YES; [self.manaView addSubview:scroll]; 代码的第一部分介绍了我的UIView ,这很好,但我不知道如何编程UIScrollView并将其添加到视图,然后将button添加到它。 UIButton *ret2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; ret2.tag = 102; ret2.frame = CGRectMake(255, 5, 60, 50); [ret2 setTitle:@"Return" forState:UIControlStateNormal]; [ret2 addTarget:self action:@selector(flipAction:) forControlEvents:UIControlEventTouchUpInside]; [scroll […]

iOS 5.0中的核心图像filter是否足够快实时video处理?

现在,苹果已经将Core Image框架移植到了iOS 5.0,我想知道:Core Image是否足够快,可以将实时滤镜和效果应用于相机video? 另外,学习iOS 5.0的Core Image框架有什么好的起点?

如何在OCMock中存根类的方法?

我经常在我的iPhone Objective-Cunit testing中发现我想要将一个类方法(例如NSUrlConnection的+ sendSynchronousRequest:returningResponse:error:方法)存根出来。 简单的例子: – (void)testClassMock { id mock = [OCMockObject mockForClass:[NSURLConnection class]]; [[[mock stub] andReturn:nil] sendSynchronousRequest:nil returningResponse:nil error:nil]; } 运行这个时,我得到: Test Case '-[WorklistTest testClassMock]' started. Unknown.m:0: error: -[WorklistTest testClassMock] : *** -[NSProxy doesNotRecognizeSelector:sendSynchronousRequest:returningResponse:error:] called! Test Case '-[WorklistTest testClassMock]' failed (0.000 seconds). 我真的很难find任何文档,但我认为OCMock不支持类方法。 我经过了很多Googlesearch之后发现了这个技巧。 它工作,但是非常麻烦: http : //thom.org.uk/2009/05/09/mocking-class-methods-in-objective-c/ 无论如何要在OCMock内做到这一点? 或者,有人可以想到一个聪明的OCMock类别对象,可以写成这样的事情?

用UIActivityIndi​​catorViewreplaceUIBarButtonItem

我想用UIActivityIndicatorViewreplace我的UIBarButtonItem (用于刷新),当刷新完成时,我想回到刷新button并删除UIActivityIndicatorView 。

核心数据的NSPrivateQueueConcurrencyType和线程之间的共享对象

iOS 5引入了一种新方法,通过使用NSPrivateQueueConcurrencyType初始化MOC,然后在performBlock:执行获取,在后台线程上快速获取数据performBlock: 核心数据的经验之一就是你不能在线程/队列之间共享pipe理对象。 执行块是否仍然如此performBlock: ? 是以下几点: [context performBlock:^{ // fetch request code NSArray *results = [context executeFetchRequest:request error:nil]; dispatch_async(dispatch_get_main_queue(), ^(void) { Class *firstObject = [results objectAtIndex:0]; // do something with firstObject }); }]; 仍然无法接受,因为我在bg队列和主队列之间共享我的结果数组/对象? 我仍然需要使用托pipe对象ID来做到这一点?