2

我已经尝试过 iCarousel,并将其添加到我的项目中。我能够放置图像。现在我正在尝试实现一种方法,当单击按钮时,轮播将旋转。我试过这段代码:

- (IBAction) spinButton:(id)sender
{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:carousel
                             cache:YES];
    [spinButton removeFromSuperview];
    [UIView commitAnimations];

}

但似乎只有轮播视图才有动画效果。

4

1 回答 1

3

以下两种更改 aries 的方法可能是您正在解决的问题,

-(void)TappedButton:(UIButton *)sender{

    UIView *view=[carousel itemViewAtIndex:sender.tag];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:YES];
    //    [spinButton removeFromSuperview];
    [UIView commitAnimations];
    NSLog(@"%d",sender.tag);
}             
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UILabel *label = nil;

    //create new view if no view is available for recycling
    if (view == nil)
    {
        view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page.png"]] autorelease];
//      label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
//      label.backgroundColor = [UIColor clearColor];
//      label.textAlignment = UITextAlignmentCenter;
//      label.font = [label.font fontWithSize:50];
//        
//        [view addSubview:label];

        UIButton *buttonForDisplay = [[[UIButton alloc] initWithFrame: view.bounds] autorelease];
        buttonForDisplay.backgroundColor=[UIColor clearColor];

        [buttonForDisplay setTitle:[NSString stringWithFormat:@"%d",index] forState:UIControlStateNormal];
        buttonForDisplay.titleLabel.font = [label.font fontWithSize:50];
        [buttonForDisplay addTarget:self action:@selector(TappedButton:) forControlEvents:UIControlEventTouchUpInside];
        [buttonForDisplay bringSubviewToFront:view];
        buttonForDisplay.tag = index;

///        view.tag=index;
        [view addSubview:buttonForDisplay];


    }
    else
    {
        label = [[view subviews] lastObject];
    }

    //set label
//  label.text = [[items objectAtIndex:index] stringValue];

    return view;
}

编辑 此方法通过您可以捕获轮播视图的参考。

- (UIView *)itemViewAtIndex:(NSInteger)index

用动画编辑

UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];  
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;  
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
于 2012-04-19T07:10:05.773 回答