iphone - 带按钮的 UIscrollview 中的动画

标签 iphone ios xcode

我尝试了 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];

}

但似乎只有轮播 View 有动画。

最佳答案

以下两种更改白羊座的方法可能会解决您的问题,

-(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;
}

编辑 通过这个方法你可以捕获轮播 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];

关于iphone - 带按钮的 UIscrollview 中的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10222386/

相关文章:

ios - Xcode - clang 失败,退出代码为 1。插件原因?

ios - 关于 appStoreReceiptURL 的问题

ios - iOS中的电话录音

iphone - 使用 Core Data 和 Magical Record 创建实例变量

ios - 如何使用 Swift 对字典数据进行分组

c# - 在哪里初始化 Xamarin.iOS 应用程序中实例化的 PCL?

swift - 创建具有动态字体大小的 UIButton,但在 UIStackView 中共享相同的字体大小

iphone - iphone 4的后台应用

iphone - 在 iTunes Connect 中删除应用程序

iphone - TableView Controller 中的方向?