Tag: 基础

日历:获取date组件,奇怪的情况

我试图找出为什么这段代码工作如此奇怪。 您可以在下面find详情: let nowDate = Date() let threeDayBeforeNowDate_t1 = Date(timeIntervalSinceNow: -60 * 60 * 24 * 3) let oneDayAfterNowDate = Date(timeIntervalSinceNow: 60 * 60 * 24 * 1) let threeDayBeforeNowDate_t2 = Date(timeIntervalSinceNow: -60 * 60 * 24 * 3) let threeDayBeforeNowDate = nowDate.addingTimeInterval(-60 * 60 * 24 * 3) let diff_1 = threeDayBeforeNowDate_t1.timeIntervalSince(nowDate) – threeDayBeforeNowDate.timeIntervalSince(nowDate) […]

如何将HTML映射到iOS中的NSAttributedString

由于NSAttributedString initWithHTML addtion只能在Mac OS上使用,而不能在iOS上使用。

在Swift中使用isKindOf

我使用Xcode 8.0testing版testing我的应用程序,但在将我的代码2.2转换为3.0之后,出现了许多未解决的错误。 在演示下面,Xcode8.0出现错误信息 1.“if”条件之后的预期“{” if annotation.isKindof: (MKUserLocation) { return nil } 第二个错误是地图工具包…我使用iskind(的:MKUserLocation)仍然不工作,它会出现另一个错误信息 2.被占用的语句块是一个未使用的闭包 if annotation.isKindof: (MKUserLocation) { return nil } 3.在通话中缺less参数标签“:” if annotation.isKind(of: MKUserLocation) { return nil }

NSAttributedString:设置FontAttributes不会改变字体

我正在尝试更改NSAttributedString上的字体。 我有一个迭代每个字符的方法,并为该字符创build一个新的NSFontAttribute字典。 但是,最后,string保持不变。 为了演示,这里是我如何设置string: UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Avenir-Book" size:14.0f]; NSDictionary *fontAttributes = [fontDescriptor fontAttributes]; [fontAttributes setValue:[NSString stringWithFormat:@"%u",[fontDescriptor symbolicTraits]] forKey:UIFontSymbolicTrait]; [mutableAttributedString setAttributes:fontAttributes range:(NSRange){0,length}]; 这将为整个string生成以下NSFontAttribute字典: Font Attributes: { NSCTFontSymbolicTrait = 2147483648; NSFontNameAttribute = "Avenir-Book"; NSFontSizeAttribute = 14; } 我通过并修改每个字符的FontAttribute来添加粗体或斜体,如下所示: for (int i = (int)range.location; i < (range.location + range.length); i++){ /* Extract Font Attributes */ NSDictionary […]

如何在iOS上使用AVMutableComposition和CALayers

我打算在使用AV可变组合的iOS视图中呈现内容。 我想把来自其中一台iPhone摄像机的video与一层中创build的内容结合起来 – 可变的组合似乎适合这里的法案,因为它可以将图层合成到video内容中。 在录制video时进行合成并不重要 – 我也很乐意将所需的数据混合到一个合成中,然后在初始录制完成之后(通过AVExportSession)呈现给文件。 我不明白的是,在AV框架的背景下,[ca]图层应该如何知道在组合期间的特定时间要绘制什么。 我的图层内容取决于时间轴,时间轴描述了图层中需要绘制的内容。 因此,如果我将一个图层embedded到可变组合中,然后通过AVExportSession导出该组合,则CALayer实例将如何知道其应该为其生成内容的时间?

AVCaptureSession的addInput导致后台audio出现毛刺

我正在制作一个video捕捉iOS应用程序,我希望能够从麦克风录制audio,同时允许播放背景音乐。 我可以做所有这些,但是只要相机的视图进入并退出前景,背景audio就会跳过(暂停一下)。 我已经隔离了AVCaptureSession addInput错误: AVCaptureSession session = [[AVCaptureSession alloc] init]; session.automaticallyConfiguresApplicationAudioSession = NO; AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil]; // this line causes the background music to skip [session addInput:audioDeviceInput]; 如何防止添加麦克风input影响背景audio? fyi – 在didFinishLaunchingWithOptions我设置AVAudioSession类别: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];

在Swift的计算属性上的KVO

只是想知道这是否可能在斯威夫特2.2,KVO上的一个计算属性!? 即: var width = 0 var height = 0 private var area : Double { get { return with * height } } self.addOberser(self, forKeyPath: "area", …… 客户端代码是否会修改with或height触发器observeValueForKeyPath? 在参与市长课堂重构之前进行检查。 KVO的语法和讨厌的一样令人讨厌,如果有人在手边有答案的话,那就算是游乐场也是不值得的(我假设答案是NO) 问候! 〜d

在Objective C中有NSArray,NSDictionary等类的可变和不可变的版本背后的逻辑是什么?

为什么像Objective-C中的常见集合类,如NSString,NSArray,NSDictionary等有一个可变的以及不可变的版本。 分别定义它们的逻辑是什么? 性能,内存pipe理还是其他?

如何判断用户是否closures我的应用程序的蜂窝数据?

虽然我的应用程序可以在没有任何互联网连接的情况下使用,但它可以与networking服务器交换数据(为了显示一些用户统计信息)。 所以我宣传应用程序为“不需要互联网连接”。 一些用户随后closures了我的应用的蜂窝数据,这应该是完全正常的。 但是,当我的应用程序尝试交换数据时,这些用户与“蜂窝数据closures[应用程序名称]”。 对话。 这对他们来说是一个烦恼,我想要阻止这些对话,并简单地跳过整个数据交换的事情。 有苹果的可达性示例代码 。 但是,虽然我closures了整个设备和应用程序的蜂窝数据的WiFi,可达性证实了一个积极的互联网连接。 报告更具体一些 Reachability Flag Status: WR t—— networkStatusForFlags 不pipe我是否启动蜂窝数据。 当然,当蜂窝数据closures时,实际上没有互联网连接,所以数据交换失败。 但无论如何,用户都会看到蜂窝数据对话框。 有没有什么办法可以检测iOS 7和iOS 8上的互联网连接是否可用,同时考虑到特定应用程序的蜂窝数据设置 – 所有操作都不会每次都通过蜂窝数据对话框来窃听用户? 我的应用程序目前没有任何设置面板,所以我想避免设置(第二,在应用程序)切换“不使用手机数据”。 另外,我不希望将数据交换限制为WiFi连接,因为每个会话只有2 KB的数据,这对于大多数用户来说不是一件大事。

AVAudioSession AVAudioSessionCategoryPlayAndRecord毛刺

我想使用AVCaptureSession录制带有audio的video。 为此我需要AudioSessionCategory AVAudioSessionCategoryPlayAndRecord ,因为我的应用程序还播放有声video。 我希望audio能够从默认扬声器中听到,我希望它能与其他audio混合。 所以我需要选项AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers 。 如果我在播放其他audio时进行以下操作,则会从另一个应用程序的audio中看到清晰的声音故障: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; 有没有办法摆脱这个故障? 当AVAudioSessionRouteChangeReasonCategoryChange从没有话筒input到话筒input时, AVAudioSessionRouteChangeReasonRouteConfigurationChange通知AVAudioSessionRouteChangeReasonCategoryChange 。 应用程序转到后台时(也可以不closuresaudio会话)也会发生configuration更改(和毛刺)。 在不closuresaudio会话的情况下从后台返回时,当AVCaptureSessionconfiguration发生变化,即相机从前向后切换时,会出现毛刺。 在这种情况下,audio路由不被触摸,并且仅在从后台返回而不closuresaudio会话时发生。 路由改变的通知被激发两次。 一次禁用麦克风,一次再次启用。 请注意,通过下载Apple的AVCamManual示例,可以很容易地重现此行为。 将以下内容添加到AAPLCameraViewController.m的viewDidLoad中: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; … session.usesApplicationAudioSession = YES; session.automaticallyConfiguresApplicationAudioSession = NO; 其他一些奇怪的事情,这可能是相关的: 首先将audio类别设置为AVAudioSessionCategoryAmbient并将其激活: […]