0

我正在使用 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 中的所有按钮都应该翻转。我该怎么做,我使用的翻转代码在这里,

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];
4

2 回答 2

0

因为与FOR相比,循环要快得多UIViewAnimation。因此,即使它正在为您的视图设置动画,您也将无法看到动画效果。

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

于 2012-08-14T12:38:05.807 回答
0

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

这是代码:

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

        [UIView setAnimationDuration:0.7];
        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];
于 2012-09-13T05:42:46.490 回答