使用Cocoa-Touch从文档目录播放下载的video

我试图让我的应用程序播放已下载到文档目录的video文件。 我知道该文件正在下载,但我似乎无法获得文件播放,这里是我的代码: -(IBAction)play{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"]; NSURL *movieURL = [NSURL fileURLWithPath:path]; _player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; [self.view addSubview:_player.view]; _player.controlStyle = MPMovieControlStyleDefault; _player.shouldAutoplay = YES; [_player setFullscreen:YES animated:YES]; [_player play]; }

将文件保存在swift 3的文件目录下?

我用这个代码将文件保存在swift 3文档目录中: fileManager = FileManager.default // let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String path = path + name let image = #imageLiteral(resourceName: "Notifications") let imageData = UIImageJPEGRepresentation(image, 0.5) let bool = fileManager?.createFile(atPath: path, contents: imageData, attributes: nil) print("bool is \(bool)") return true 但正如你所看到的,我没有使用filemanager来获取文档目录path,因为filemanager只给出URL而不是string。 问题: 如何从文件pipe理器获取string? […]

CGAffineTransformMakeRotation负M_PI

我正在使用CGAffineTransformMakeRotation来旋转一个animation块内的UIView ,我想逆时针旋转180º 。 但是,当我把 myView.animateWithDuration(0.5) myView.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI)) 它仍然顺时针旋转。 令我困惑的是,如果我手动写入M_PI的值,它就会按预期工作 // this will rotate counterclockwise myView.transform = CGAffineTransformMakeRotation(CGFloat(-3.14159265358979)) 为什么这种行为? 编辑:添加我正在使用animation块

AVURLAsset无法加载远程文件

我有一个使用AVURLAsset的问题。 NSString * const kContentURL = @ "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"; … NSURL *contentURL = [NSURL URLWithString:kContentURL]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:contentURL options:nil]; [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:^{ … NSError *error = nil; AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey error:&error]; … } 在完成块中,状态是AVKeyValueStatusFailed,错误消息是“无法打开”。 我见过的所有例子,使用本地文件,所以也许有使用远程文件的问题… 问候,昆汀

了解iBeacon数据:电源字段和其他字节

我是蓝牙系统的新手,我正试图理解用于苹果新技术的数据:iBeacon。 已经有一些很好的答案解释了它是如何工作的,我一直在阅读我能find的所有东西(尤其是蓝牙规范)。 不过,我错过了一些观点,我将首先举个例子:(我正在使用设置广告数据命令 ,这里忽略了OGF之前的hcitool cmd ) 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 00 00 00 C5 00 我将在这里列出我不了解或find的信息。 有没有关于OGF的任何信息(这里是0x08 )? 我知道它代表的是OpCode Group Field,但是跟OGF一样,OCF没有find任何东西。 02 01 1A 1A字节代表什么? 我知道第一个字节1E告诉了其余数据的长度,在那行之后,从FF开始,你得到了制造商的特定数据。 但是我找不到这4个字节的内容。 功率字节是如何工作的? 这是C5 。 […]

iPhone应用程序的设置包

对,我正在开发一个有两个设置Dev和Live的应用程序。 有没有一种方法根据应用程序是否正在运行或仍在开发中来区分应该使用哪一个设置,还是必须在整个设置文件生效之前更改整个设置文件。 我不确定如何把这个,所以如果你不确定的地方问。

在第一个月,NSDate返回错误的date

我的应用程序使用[NSDatedate]函数获取当前date。 上午除了每个月的第一天外,其他日子的工作都很好。 即遵循以下步骤: 将系统date设置为01 – 2011年6月和00.00午夜至5.59 AM之间的时间。 使用以下代码: NSLog(@"Current Date :: %@",[NSDate date]); O / P是::当前date:: 2011-05-31 19:40:21 +0000 所需的O / P是::当前date:: 2011-06-01 00:00:00(即所设定的时间)+0000 也从6上午它工作正常。 这是什么原因? 其实我不希望string格式的NSDate,但我想要的是NSDatedate对象对应于当前月份的第一个date。 为此,我使用下面的代码片段: NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDatedate]]; [comp setDay:1]; NSDate *firstDayOfMonthDate = [gregorian dateFromComponents:comp]; [gregorian release]; […]

当应用程序处于后台状态Swift时暂停计时器

我的ViewController.swift func startTimer() { timer = NSTimer().scheduleTimerWithTimerInvterval(1.0,target: self,selctor: Selector("couting"),userinfo: nil, repeats: true) } func pauseTimer() { timer.invalidate() println("pausing timer") } 这是appDelegate.swift func applicateWillResignActive(application: UIApplication) { viewController().pauseTimer() println("closing app") } 它正在打印暂停计时器和closures应用程序,但是当我再次打开我看到它永远不会暂停。 我如何正确地做到这一点?

解除模态视图控制器后,框架不反映自动布局约束

我使用iOS 6,分页UIScrollView和纯自动布局。 简介:我创build了一个滚动页面内容的视图控制器。 一些视图是在故事板中创build和configuration的,其他则是以编程方式。 这是视图层次结构: – Main view (storyboard) – UIScrollView (storyboard) – content view (programmatically) – subviews representing pages of content (programmatically) 在IB中configuration滚动视图的约束。 以下是我如何在代码中configuration内容视图的约束: – (void)viewDidLoad { // ABPageScrollerContentView is a subclass of UIView; it overrides intrinsicContentSize; the size is calculated without referencing the scroll view's dimensions self.contentView = [[ABPageScrollerContentView alloc] init]; self.contentView.translatesAutoresizingMaskIntoConstraints = […]

UICollectoin查看水平卷轴与项目间距

我正在使用我的一些图像的集合视图。 每个图像应该以屏幕大小显示,因此一个单元格具有屏幕宽度。 minimumInterItemSpacing的minimumInterItemSpacing是25.所以现在的问题是,如果我滚动,集合视图不滚动到下一个图像的开始,而是interItemSpacing的开始。 我们来举个例子: Image/Cell width = 320 CollectionView's interItemSpacing = 25 如果我滚动一个页面,那么滚动视图的内容偏移是在320而不是在345,这意味着第二个单元不在屏幕的中心。 如何解决这个问题? 有什么build议么?