翻转动画无法在GMGridview中使用

时间:2012-08-14 12:17:34

标签: iphone ipad ios5 xcode4.2 gmgridview

我正在使用GMGridview的应用程序中工作。我在cellforItems方法中添加了按钮。 -

 (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index
{
    NSLog(@"Creating view indx %d", index);

    CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];

    GMGridViewCell *cell = [gridView dequeueReusableCell];

    if (!cell) 
    {
        cell = [[GMGridViewCell alloc] init];
        cell.deleteButtonIcon = [UIImage imageNamed:@"close_x.png"];
        cell.deleteButtonOffset = CGPointMake(-15, -15);

    }

    [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];


     btn = [UIButton buttonWithType:UIButtonTypeCustom];
     [btn setTag:index];


    [btn setFrame:CGRectMake(0, 0,size.width, size.height)];
    NSLog(@"button frame is %@",btn);

    [[btn layer] setBorderColor:[UIColor redColor].CGColor];
    [[btn layer]setBorderWidth:2.0f];
    [btn addTarget:self action:@selector(SegmentChange:) forControlEvents:UIControlEventTouchUpInside];

    cell.contentView = btn;
    //int btntag=btn.tag;

return cell;

然后我用翻转所有按钮的方法,但它不起作用,我想要的是当我点击翻转按钮时gridview中的所有按钮都应该flip.ow我可以这样做,翻转的代码我使用在这里,

for(ll=0;ll<[Image_array count];ll++) 
    {
       // [UIView setAnimationDelay:2.0];
        [UIView beginAnimations:@"BackButton" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:12.0];

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:btn cache:YES];
        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];
        [btn setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal];
        [arr_check replaceObjectAtIndex:ll withObject:@"uncheck"];

        front = NO;


    }
       [_gmGridView reloadData];

2 个答案:

答案 0 :(得分:0)

由于FOR循环比UIViewAnimation快得多。因此,即使它为您的视图设置动画,您也无法看到动画效果。

您可以使用NSTimerUIViewAnimation委托方法来确定是否完成了一个视图翻转事件。然后从委托方法(UIViewAnimation)开始,您可以启动另一个视图动画。

答案 1 :(得分:0)

我已经从for循环中删除了代码并在cellForItemAtIndexpath中使用了相同的代码并使用单元格来翻转而不是按钮

这是代码:

        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell cache:YES];

        [UIView setAnimationDuration:0.7];
        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];