欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用iOS開發(fā)實現(xiàn)翻轉(zhuǎn)撲克牌動畫的方法

 更新時間:2017年07月17日 10:18:20   作者:斌Jonas  
這篇文章主要給大家介紹了關(guān)于利用iOS開發(fā)實現(xiàn)翻撲克牌動畫的方法,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來跟著小編一起學習學習吧。

前言

本文主要給大家介紹的關(guān)于利用iOS開發(fā)實現(xiàn)翻轉(zhuǎn)撲克牌動畫的方法,分享出來供大家參考學習,下面話不多說,來一起看看詳細的介紹吧。

動畫效果


實現(xiàn)原理

實現(xiàn)原理就是創(chuàng)建三個撲克牌pockerView , 先在撲克牌上添加一個imageview,作為牌的背面。然后實現(xiàn)翻轉(zhuǎn)動畫,在翻轉(zhuǎn)的時候?qū)mageview移除,添加另一個imageview作為正面。

核心代碼:

方法一: 翻轉(zhuǎn)動畫,內(nèi)部實現(xiàn)還是方法二

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

方法二 :UIView動畫

[UIView beginAnimations:@"aa" context:nil];
 [UIView setAnimationDuration:_duration];
 [UIView setAnimationCurve:UIViewAnimationCurveLinear];
 [view.imgview1 removeFromSuperview];
 [view addSubview:view.imgview2];
 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];
 [UIView commitAnimations];

完整代碼:

ViewController.m文件代碼

#import "ViewController.h"
#import "PockerView.h"
@interface ViewController ()
// 記錄翻第幾張牌
@property(nonatomic,assign)NSInteger index;
// 動畫時間
@property(nonatomic,assign)CGFloat duration;
@end

@implementation ViewController

 

- (void)viewDidLoad {
 [super viewDidLoad];

 self.view.backgroundColor = [UIColor blackColor];
 _duration = 0.5;
 _index = 0;
 NSArray *arr = @[@"2.jpg",@"3.jpg",@"4.jpg"];
 // 循環(huán)創(chuàng)建3張撲克牌
 for (int i = 0; i < 3; i++) {
  PockerView *pocker = [[PockerView alloc]initWithFrame:CGRectMake(100 + 80 * i, 100, 100, 150) imageName:arr[i]];
  pocker.tag = 1000 + i;
  [self.view addSubview:pocker];
 }
}

 

// 點擊空白處觸發(fā)
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
 // 執(zhí)行動畫
 [self executeAnimation];
}


// 執(zhí)行動畫
- (void)executeAnimation{
 // 根據(jù)tag值取到撲克牌
 PockerView *pocker = [self.view viewWithTag:1000+ _index];
 // 方法一
 [self animationWithView:pocker];
 // 方法二
// [self rotateWithView:pocker];
}

// 翻牌動畫方法一(內(nèi)部實現(xiàn)還是方法二)
- (void)animationWithView:(PockerView *)view{
 // 延時方法 正在翻轉(zhuǎn)的牌翻轉(zhuǎn)一半的時候把它移到視圖最上面來
 [self performSelector:@selector(delayAction:) withObject:view afterDelay:_duration / 2];

 // 翻轉(zhuǎn)動畫
 UIViewAnimationOptions option = UIViewAnimationOptionTransitionFlipFromLeft;
 [UIView transitionWithView:view      duration:_duration
      options:option
     animations:^ {
      [view.imgview1 removeFromSuperview];
      [view addSubview:view.imgview2];
     }
     completion:^(BOOL finished){
      _index++;
      if (_index < 3) {
       [self executeAnimation];
      }
 }];
}

// 延時方法
- (void)delayAction:(UIView *)view{
 [self.view bringSubviewToFront:view];
}


- (void)delayAction2{
 _index++;
 if (_index < 3) {
  [self executeAnimation];
 }
}


// 方法二
- (void)rotateWithView:(PockerView *)view{

 [self performSelector:@selector(delayAction:) withObject:view afterDelay:_duration / 2];
 [self performSelector:@selector(delayAction2) withObject:nil afterDelay:_duration];
 [UIView beginAnimations:@"aa" context:nil];
 [UIView setAnimationDuration:_duration];
 [UIView setAnimationCurve:UIViewAnimationCurveLinear];
 [view.imgview1 removeFromSuperview];
 [view addSubview:view.imgview2];
 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];
 [UIView commitAnimations];
}
@end

PockerView.h文件代碼

//
// PockerView.h
// 翻牌
//
// Created by 斌 on 2017/4/20.
// Copyright © 2017年 斌. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface PockerView : UIView

@property(nonatomic,strong)UIImageView *imgview1;
@property(nonatomic,strong)UIImageView *imgview2;

- (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageName;

@end

PockerView.m文件代碼

//
// PockerView.m
// 翻牌
//
// Created by 斌 on 2017/4/20.
// Copyright © 2017年 斌. All rights reserved.
//

#import "PockerView.h"

@implementation PockerView

- (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageName{
 self = [super initWithFrame:frame];
 if (self) {

  // 設(shè)置陰影
  self.layer.shadowColor = [UIColor blackColor].CGColor;
  self.layer.shadowOffset = CGSizeMake(-10, 0);
  self.layer.shadowOpacity = 0.3;

  // 牌的背面
  self.imgview1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  _imgview1.backgroundColor = [UIColor redColor];
  _imgview1.image = [UIImage imageNamed:@"1.jpeg"];
  [self addSubview:_imgview1];
  self.imgview1.layer.cornerRadius = 10;
  self.imgview1.clipsToBounds = YES;
  self.imgview1.layer.borderWidth = 5;
  self.imgview1.layer.borderColor = [[UIColor whiteColor] CGColor];

  // 牌的正面
  self.imgview2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  _imgview2.backgroundColor = [UIColor redColor];
  _imgview2.image = [UIImage imageNamed:imageName];
  self.imgview2.layer.cornerRadius = 10;
  self.imgview2.clipsToBounds = YES;
  self.imgview2.layer.borderWidth = 5;
  self.imgview2.layer.borderColor = [[UIColor whiteColor] CGColor];
 }
 return self;
}
@end

github鏈接地址:https://github.com/jiangbin1993/pockerRotateAnimation.git

本地下載地址:http://xiazai.jb51.net/201707/yuanma/pockerRotateAnimation(jb51.net).rar

總結(jié)

以上就是這篇文章的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • 分享一些iOS開發(fā)實用的小技巧

    分享一些iOS開發(fā)實用的小技巧

    這篇文章主要給大家分享了一些iOS開發(fā)實用的小技巧,這些小技巧在大家開發(fā)iOS的時候還是相當實用,有需要的朋友們下面來一起看看吧。
    2016-09-09
  • 單純聊一聊iOS10適配

    單純聊一聊iOS10適配

    這篇文章主要為大家簡單介紹了iOS10適配的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • ios開發(fā)Flutter構(gòu)建todo?list應用

    ios開發(fā)Flutter構(gòu)建todo?list應用

    這篇文章主要為大家介紹了ios開發(fā)Flutter構(gòu)建todo?list應用實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • IOS 數(shù)據(jù)存儲詳解及實例代碼

    IOS 數(shù)據(jù)存儲詳解及實例代碼

    這篇文章主要介紹了IOS 數(shù)據(jù)存儲詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • iOS實現(xiàn)只有底部邊框線的輸入框示例代碼

    iOS實現(xiàn)只有底部邊框線的輸入框示例代碼

    這篇文章給大家分享了一種利用iOS實現(xiàn)只有底部邊框線的輸入框,其實這個效果也挺常見的,本文給出了示例代碼,下面來看看如何實現(xiàn)這種效果。
    2016-09-09
  • iOS開發(fā)之tableView實現(xiàn)左滑刪除功能

    iOS開發(fā)之tableView實現(xiàn)左滑刪除功能

    我們在使用一些應用的時候,在滑動一些聯(lián)系人的某一行的時候,會出現(xiàn)刪除、置頂、更多等等的按鈕,下面這篇文章主要就介紹了iOS用tableView實現(xiàn)左劃刪除功能的方法,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2017-01-01
  • IOS判斷字符串是否有空格實例

    IOS判斷字符串是否有空格實例

    在我們大家日常開發(fā)的時候,經(jīng)常會需要對注冊,登錄,忘記密碼等功能的密碼進行判斷是否包含空格,下面這篇文章給大家分享了自己封裝的一個方法,有需要的可以參考借鑒。
    2016-09-09
  • iOS優(yōu)化UITableViewCell高度計算的一些事兒

    iOS優(yōu)化UITableViewCell高度計算的一些事兒

    這iOS開發(fā)中對于UITableViewCell高度自適應的文章已經(jīng)很多很多,但都不是自己所需要的,下面篇文章主要給大家介紹了關(guān)于iOS優(yōu)化UITableViewCell高度計算的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2018-11-11
  • iOS小組件開發(fā)之WidgetKit功能講解

    iOS小組件開發(fā)之WidgetKit功能講解

    這篇文章主要為大家介紹了iOS小組件開發(fā)WidgetKit功能講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • iOS實現(xiàn)動態(tài)元素的引導圖效果

    iOS實現(xiàn)動態(tài)元素的引導圖效果

    這篇文章給大家介紹了iOS實現(xiàn)動態(tài)元素的引導圖效果的步驟,文章給出了示例代碼介紹的很詳細,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-09-09

最新評論