- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor whiteColor];
self.title=@"春节";
NSArray*array=@[@"春联",@"鞭炮",@"饺子",@"除夕",@"春晚",@"拜年",@"压岁钱",@"熬年",@"拜财神"];
CGFloat ww=ScreenWidth/3.0;
for (int j=0; j<3; j++) {
for (int i=0; i<3; i++) {
FlipView*view=[[FlipView alloc]initWithFrame:CGRectMake(ww*i,NavHeight+ww*j, 80, 80)];
view.center=CGPointMake(ww*i+ww/2.0, NavHeight+ww*j+ww/2.0);
view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:view];
UIView*backView=[[UIView alloc]initWithFrame:view.bounds];
backView.backgroundColor=[UIColor whiteColor];
UIView*frontView=[[UIView alloc]initWithFrame:view.bounds];
frontView.backgroundColor=[UIColor whiteColor];
UIButton*button=[UIButton buttonWithType:(UIButtonTypeSystem)];
button.frame=view.bounds;
[button setTitle:array[j*3+i] forState:(UIControlStateNormal)];
button.tag=100+j*3+i;
view.tag=button.tag+100;
[button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)];
[backView addSubview:button];
view.backView=backView;
UIImageView*imgView=[[UIImageView alloc]initWithFrame:CGRectMake(18, 18, 44, 44)];
imgView.image=[UIImage imageNamed:array[j*3+i]];
imgView.userInteractionEnabled=YES;
imgView.tag=button.tag+200;
UITapGestureRecognizer*tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction:)];
[imgView addGestureRecognizer:tapGesture];
[frontView addSubview:imgView];
view.frontView=frontView;
if (j==0) {
view.flipType=ViewFlipTypeCurlUpAndDown;
view.backView.backgroundColor=[UIColor purpleColor];
view.frontView.backgroundColor=[UIColor redColor];
}else if (j==1)
{
view.flipType=ViewFlipTypeLeftAndRight;
view.backView.backgroundColor=[UIColor brownColor];
view.frontView.backgroundColor=[UIColor blueColor];
}else
{
view.flipType=ViewFlipTypeTopAndBottom;
view.backView.backgroundColor=[UIColor magentaColor];
view.frontView.backgroundColor=[UIColor cyanColor];
}
}
}
}
-(void)tapGestureAction:(UITapGestureRecognizer*)tap
{
UIImageView*imgView=(UIImageView*)tap.view;
FlipView*view=[self.view viewWithTag: imgView.tag-100]; //让view翻转
view.isBeginFlip=YES;
}
-(void)buttonClick:(UIButton*)button
{
FlipView*view=[self.view viewWithTag: button.tag+100]; //让view翻转 view.isBeginFlip=YES;
}
|