OStack程序员社区-中国程序员成长平台

标题: iphone - 带有按钮的 UIscrollview 中的动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 13:17
标题: iphone - 带有按钮的 UIscrollview 中的动画

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

- (IBAction) spinButtonid)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 有动画效果。



Best Answer-推荐答案


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

-(void)TappedButtonUIButton *)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 *)carouseliCarousel *)carousel viewForItemAtIndexNSUInteger)index reusingViewUIView *)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 actionselector(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 *)itemViewAtIndexNSInteger)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/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4