<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # CAReplicatorLayer `CAReplicatorLayer`的目的是為了高效生成許多相似的圖層。它會繪制一個或多個圖層的子圖層,并在每個復制體上應用不同的變換。看上去演示能夠更加解釋這些,我們來寫個例子吧。 ## 重復圖層(Repeating Layers) 清單6.8中,我們在屏幕的中間創建了一個小白色方塊圖層,然后用`CAReplicatorLayer`生成十個圖層組成一個圓圈。`instanceCount`屬性指定了圖層需要重復多少次。`instanceTransform`指定了一個`CATransform3D`3D變換(這種情況下,下一圖層的位移和旋轉將會移動到圓圈的下一個點)。 變換是逐步增加的,每個實例都是相對于前一實例布局。這就是為什么這些復制體最終不會出現在同意位置上,圖6.8是代碼運行結果。 清單6.8 用`CAReplicatorLayer`重復圖層 ~~~ @interface ViewController () @property (nonatomic, weak) IBOutlet UIView *containerView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //create a replicator layer and add it to our view CAReplicatorLayer *replicator = [CAReplicatorLayer layer]; replicator.frame = self.containerView.bounds; [self.containerView.layer addSublayer:replicator]; //configure the replicator replicator.instanceCount = 10; //apply a transform for each instance CATransform3D transform = CATransform3DIdentity; transform = CATransform3DTranslate(transform, 0, 200, 0); transform = CATransform3DRotate(transform, M_PI / 5.0, 0, 0, 1); transform = CATransform3DTranslate(transform, 0, -200, 0); replicator.instanceTransform = transform; //apply a color shift for each instance replicator.instanceBlueOffset = -0.1; replicator.instanceGreenOffset = -0.1; //create a sublayer and place it inside the replicator CALayer *layer = [CALayer layer]; layer.frame = CGRectMake(100.0f, 100.0f, 100.0f, 100.0f); layer.backgroundColor = [UIColor whiteColor].CGColor; [replicator addSublayer:layer]; } @end ~~~ ![](https://box.kancloud.cn/2015-12-24_567bc2023a85c.png) 圖6.8 用`CAReplicatorLayer`創建一圈圖層 注意到當圖層在重復的時候,他們的顏色也在變化:這是用`instanceBlueOffset`和`instanceGreenOffset`屬性實現的。通過逐步減少藍色和綠色通道,我們逐漸將圖層顏色轉換成了紅色。這個復制效果看起來很酷,但是`CAReplicatorLayer`真正應用到實際程序上的場景比如:一個游戲中導彈的軌跡云,或者粒子爆炸(盡管iOS 5已經引入了`CAEmitterLayer`,它更適合創建任意的粒子效果)。除此之外,還有一個實際應用是:反射。 ## 反射 使用`CAReplicatorLayer`并應用一個負比例變換于一個復制圖層,你就可以創建指定視圖(或整個視圖層次)內容的鏡像圖片,這樣就創建了一個實時的『反射』效果。讓我們來嘗試實現這個創意:指定一個繼承于`UIView`的`ReflectionView`,它會自動產生內容的反射效果。實現這個效果的代碼很簡單(見清單6.9),實際上用`ReflectionView`實現這個效果會更簡單,我們只需要把`ReflectionView`的實例放置于Interface Builder(見圖6.9),它就會實時生成子視圖的反射,而不需要別的代碼(見圖6.10). 清單6.9 用`CAReplicatorLayer`自動繪制反射 ~~~ #import "ReflectionView.h" #import @implementation ReflectionView + (Class)layerClass { return [CAReplicatorLayer class]; } - (void)setUp { //configure replicator CAReplicatorLayer *layer = (CAReplicatorLayer *)self.layer; layer.instanceCount = 2; //move reflection instance below original and flip vertically CATransform3D transform = CATransform3DIdentity; CGFloat verticalOffset = self.bounds.size.height + 2; transform = CATransform3DTranslate(transform, 0, verticalOffset, 0); transform = CATransform3DScale(transform, 1, -1, 0); layer.instanceTransform = transform; //reduce alpha of reflection layer layer.instanceAlphaOffset = -0.6; } ? - (id)initWithFrame:(CGRect)frame { //this is called when view is created in code if ((self = [super initWithFrame:frame])) { [self setUp]; } return self; } - (void)awakeFromNib { //this is called when view is created from a nib [self setUp]; } @end ~~~ ![](https://box.kancloud.cn/2015-12-24_567bc20265cfb.png) 圖6.9 在Interface Builder中使用`ReflectionView` ![](https://box.kancloud.cn/2015-12-24_567bc2029bed9.png) 圖6.10?`ReflectionView`自動實時產生反射效果。 開源代碼`ReflectionView`完成了一個自適應的漸變淡出效果(用`CAGradientLayer`和圖層蒙板實現),代碼見?[https://github.com/nicklockwood/ReflectionView](https://github.com/nicklockwood/ReflectionView)
                  <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>

                              哎呀哎呀视频在线观看