<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # AVPlayerLayer 最后一個圖層類型是`AVPlayerLayer`。盡管它不是Core Animation框架的一部分(AV前綴看上去像),`AVPlayerLayer`是有別的框架(AVFoundation)提供的,它和Core Animation緊密地結合在一起,提供了一個`CALayer`子類來顯示自定義的內容類型。 `AVPlayerLayer`是用來在iOS上播放視頻的。他是高級接口例如`MPMoivePlayer`的底層實現,提供了顯示視頻的底層控制。`AVPlayerLayer`的使用相當簡單:你可以用`+playerLayerWithPlayer:`方法創建一個已經綁定了視頻播放器的圖層,或者你可以先創建一個圖層,然后用`player`屬性綁定一個`AVPlayer`實例。 在我們開始之前,我們需要添加AVFoundation到我們的項目中。然后,清單6.15創建了一個簡單的電影播放器,圖6.16是代碼運行結果。 清單6.15 用`AVPlayerLayer`播放視頻 ~~~ #import "ViewController.h" #import #import @interface ViewController () @property (nonatomic, weak) IBOutlet UIView *containerView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //get video URL NSURL *URL = [[NSBundle mainBundle] URLForResource:@"Ship" withExtension:@"mp4"]; //create player and player layer AVPlayer *player = [AVPlayer playerWithURL:URL]; AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; //set player layer frame and attach it to our view playerLayer.frame = self.containerView.bounds; [self.containerView.layer addSublayer:playerLayer]; //play the video [player play]; } @end ~~~ ![](https://box.kancloud.cn/2015-12-24_567bc205e5439.png) 圖6.16 用`AVPlayerLayer`圖層播放視頻的截圖 我們用代碼創建了一個`AVPlayerLayer`,但是我們仍然把它添加到了一個容器視圖中,而不是直接在controller中的主視圖上添加。這樣其實是為了可以使用自動布局限制使得圖層在最中間;否則,一旦設備被旋轉了我們就要手動重新放置位置,因為Core Animation并不支持自動大小和自動布局(見第三章『圖層幾何學』)。 當然,因為`AVPlayerLayer`是`CALayer`的子類,它繼承了父類的所有特性。我們并不會受限于要在一個矩形中播放視頻;清單6.16演示了在3D,圓角,有色邊框,蒙板,陰影等效果(見圖6.17). 清單6.16 給視頻增加變換,邊框和圓角 ~~~ - (void)viewDidLoad { ... //set player layer frame and attach it to our view playerLayer.frame = self.containerView.bounds; [self.containerView.layer addSublayer:playerLayer]; //transform layer CATransform3D transform = CATransform3DIdentity; transform.m34 = -1.0 / 500.0; transform = CATransform3DRotate(transform, M_PI_4, 1, 1, 0); playerLayer.transform = transform; ? //add rounded corners and border playerLayer.masksToBounds = YES; playerLayer.cornerRadius = 20.0; playerLayer.borderColor = [UIColor redColor].CGColor; playerLayer.borderWidth = 5.0; //play the video [player play]; } ~~~ ![](https://box.kancloud.cn/2015-12-24_567bc206182ee.png) 圖6.17 3D視角下的邊框和圓角`AVPlayerLayer`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看