翻转
showFront=!showFront;
[UIView transitionWithView:self duration:0.65f
options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
self.iFrontView.hidden = !self.showFront;
self.iBackImageView.hidden = self.showFront;
} completion:^(BOOL finished) {
}];
洗牌- (void)xipai{
self.count=0;
if ([self.iType isEqualToNumber:@1]) {
self.iCardViewRandomArray=[NSMutableArray arrayWithArray:@[@0,@1,@2,@3,@4,@5,@6,@7,@8]];
for (int i=0;i<9;i++){
NSNumber* context=[NSNumber numberWithInt:i];
[UIView beginAnimations:nil context:(void*)context];
[UIView setAnimationDuration:0.1];
int xTo = 320/8*7;
int xFrom = 320/8;
CGFloat x = (CGFloat)(xFrom + arc4random() % (xTo - xFrom+1));
int yFrom = ([UIScreen mainScreen].bounds.size.height-64-320/8*6)/2;
int yTo = yFrom+320/8*6;
CGFloat y = (CGFloat)(yFrom + arc4random() % (yTo - yFrom+1));
UIView* v=[self.iCardViewArray objectAtIndex:i];
v.center=CGPointMake(x,y);
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}
}
}
-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([self.iType isEqualToNumber:@1]) {
int i = [(__bridge NSNumber*)context intValue];
if (i==8){
self.count++;
}
if (self.count==MAX_LOOP){
// NSLog(@"finish");
//最后一个图结束
if (i==0) {
self.iCanChooseGift = YES;
self.iGetGiftBtn.selected = NO;
[self.iGetGiftBtn setUserInteractionEnabled:YES];
}
return;
}
//next iteration x,y
CGFloat x;
CGFloat y;
if (self.count==MAX_LOOP-1){
int lowerBound = 0;
int upperBound = self.iManCardViewRandomArray.count;
int rndIndex = lowerBound + arc4random() % (upperBound - lowerBound);
NSNumber* pickedNumber=[self.iManCardViewRandomArray objectAtIndex:rndIndex];
[self.iManCardViewRandomArray removeObjectAtIndex:rndIndex];
int y_index=pickedNumber.intValue/3;
int x_index=pickedNumber.intValue%3;
float horGap = (320*[self getScaleRatio]-104*[self getScaleRatio]*3)/4;
float verGap = (self.cardViewContentHeight-138*[self getScaleRatio]*3)/4;
y=verGap*(y_index+1) +50+y_index*138*[self getScaleRatio];
x=horGap*(x_index+1) +x_index*104*[self getScaleRatio];
}
else{
int xTo = 320*[self getScaleRatio]/8*7;//-104*[self getScaleRatio];
int xFrom = 320*[self getScaleRatio]/8;
x = (CGFloat)(xFrom + arc4random() % (xTo - xFrom+1));
int yFrom = ([UIScreen mainScreen].bounds.size.height-64-320*[self getScaleRatio]/8*6)/2;
int yTo = yFrom+320*[self getScaleRatio]/8*6;
y = (CGFloat)(yFrom + arc4random() % (yTo - yFrom+1));
}
// 最后几次会变慢
// if ( self.count>=MAX_LOOP-5 && self.count !=MAX_LOOP-1) {
// [UIView beginAnimations:nil context:context];
// [UIView setAnimationDuration:0.1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//
// UIView* v=[self.iManCardViewArray objectAtIndex:i];
//
// // NSLog(@"Count=%d Finished=%@ i=%d",self.count,finished,i);
//
// v.center=CGPointMake(x,y);
//
// [UIView setAnimationDelegate:self];
// [UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
// [UIView commitAnimations];
//
// }
// else
if (self.count ==MAX_LOOP-1){
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.1];
UIView* v=[self.iManCardViewArray objectAtIndex:i];
[v setFrame:CGRectMake(x,y, 104*[self getScaleRatio], 138*[self getScaleRatio])];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}
else{
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.1];
UIView* v=[self.iManCardViewArray objectAtIndex:i];
v.center=CGPointMake(x,y);;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}
}
}