图片翻转

1、



引入两个framework(Builds Phases->Link Binary With Libraries)





加入两张图片,m_6.jpg和m_7.jpg。

打开.xib文件,拖入一个view视图,将其类名改为UIControl,再拖入两个image view视图,将其图片设置为m_6.jpg和m_7.jpg



为Control和两个image view 视图关联变量

//
//  ViewController.h
//  图片翻转
//
//  Created by Rio.King on 13-9-13.
//  Copyright (c) 2013年 Rio.King. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIControl *container;//Control的关联变量
@property (retain, nonatomic) IBOutlet UIImageView *image1;
@property (retain, nonatomic) IBOutlet UIImageView *image2;

@end

在ViewController.m文件中做如下实现:

//
//  ViewController.m
//  图片翻转
//
//  Created by Rio.King on 13-9-13.
//  Copyright (c) 2013年 Rio.King. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeCard:)];
    [tap setNumberOfTapsRequired:1];
    self.container.backgroundColor = [UIColor clearColor];
    self.container.userInteractionEnabled = YES;
    [self.container addGestureRecognizer:tap];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) changeCard:(UITapGestureRecognizer *)gesture {
    CGContextRef context=UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.container cache:YES];
    
    if (self.image1.superview){
        [self.image1 removeFromSuperview];
        [self.container addSubview:self.image2];
    } else {
        [self.image2 removeFromSuperview];
        [self.container addSubview:self.image1];
    }
    
    
    [UIView setAnimationDelegate:self.container];
    [UIView commitAnimations];
    
}
- (void)dealloc {
    [_container release];
    [_image1 release];
    [_image2 release];
    [super dealloc];
}
@end

去掉Use Autolayout这个选项

最后修改这个,如图


运行就可以看到结果了。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值