gpt4 book ai didi

iphone - Uiscrollview 中带有按钮的动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:57 24 4
gpt4 key购买 nike

我已经试用了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com