小编ani*_*hin的帖子

仅允许在一个视图控制器上进行自动旋转

在我的项目中,我只允许纵向旋转,但对于一个ViewController我想启用景观.我提出这个ViewController因为ModalViewController,我已经使用方法试过- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation或iOS 6的方法,如-(NSUInteger) supportedInterfaceOrientations,但没有实际工作.虽然这些方法被调用,但视图没有旋转.

在此之后,我试图通过听取这些通知的myslef来旋转它:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotate:)
                                             name:UIDeviceOrientationDidChangeNotification
                                           object:nil];
Run Code Online (Sandbox Code Playgroud)

但即使我能够手动旋转viewin方法didRotate:它非常凌乱,我无法旋转StatusBar.

我真的很想使用标准方法shouldAutorotateToInterfaceOrientation,但我不知道如何.任何人?

objective-c uiviewcontroller ios

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

防止AVPlayer取消背景音频

在我的应用程序中,我使用AVPlayer播放简单的视频.这些视频没有任何音轨.问题是,当我播放它们时,所有背景音乐(不是来自我的应用程序)都会停止.我该如何防止这种情况?

有没有办法用AVPlayer播放视频而不取消背景音乐?

我的代码是:

let urlAsset = AVURLAsset(URL: urlLocal, options: nil)
let item = AVPlayerItem(asset: urlAsset)
self.videoPlayer = AVPlayer(playerItem: item)

if let player = self.videoPlayer {
    self.videoLayer = AVPlayerLayer(player: player)
    if let layer = self.videoLayer {

        layer.frame = self.view.bounds
        self.view.layer.addSublayer(layer)

        NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoPlayerDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification , object: nil)

        player.actionAtItemEnd = AVPlayerActionAtItemEnd.None
        player.play()
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

audio ios avplayer swift

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

有没有使用UIManagedDocument的好例子?

我刚开始一个新的iOS项目,并选择将Core Data与UIManagedDocument一起使用.不幸的是,这是一个新类,所以没有很多例子可以使用它.作为初学者,我真的想学习一些关于UIManagedDocument的示例代码或教程.

有没有关于在iOS上使用UIManagedDocument和Core Data的好例子或教程?

core-data ios

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

UIView轮换不能发生两次

在我的UITableViewCell中我有UIImageView,我希望每次用户点击该行时旋转180°(didSelectRowAtIndexPath :).代码很简单:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     UITableViewCell *curCell = [self.tableView cellForRowAtIndexPath:indexPath];
     UIImageView *imgArrow = (UIImageView*)[curCell viewWithTag:3];
     [UIView animateWithDuration:0.3 animations:^{imgArrow.transform = CGAffineTransformMakeRotation(M_PI);}];
 }
Run Code Online (Sandbox Code Playgroud)

问题是这总是只发生一次 - 用户第一次点击单元格时,imgArrow正确旋转,但是当单击第二次单元格时它不会旋转回来.为什么?

感谢帮助!

iphone core-graphics rotation ios

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