当我按下后退按钮时。 iCarousel
仍然显示1秒钟。为什么会发生这种情况以及如何阻止这种情况。我使用故事板创建了一个iCarosel视图..
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [idOfAllWords count];
}
- (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] initWithFrame:CGRectMake(0, 0, 250.0f, 250.0f)];
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
}
else
{
label = (UILabel *)[view viewWithTag:1];
}
Words *word=nil;
word=idOfAllWords[index];
label.text =word.Name;
return view;
}
答案 0 :(得分:10)
隐藏和取消隐藏不是解决方案。你需要的只是一行:
yourCarousel.clipsToBounds = YES;
答案 1 :(得分:0)
我实际上试图重现你的问题并且确实看到当“弹出”或后退按钮发生时旋转木马视图停留一秒钟。当您转动旋转木马然后按下后退按钮时尤其会发生这种情况。作为一种解决方法,我能够通过在viewWillDisappear
方法中隐藏iCarousel来修复它。
- (void)viewWillDisappear:(BOOL)animated
{
[YOUR_CAROUSEL_NAME setHidden:YES]; //This sets the carousel to be hidden when you press Back button
}
如果看起来突然隐藏,您可以尝试在动画块内设置alpha为0.0。像这样:
- (void)viewWillDisappear:(BOOL)animated
{
//[YOUR_CAROUSEL_NAME setHidden:YES];
[UIView animateWithDuration:0.2f animations:^{
[YOUR_CAROUSEL_NAME setAlpha:0.0f]; //This makes the carousel hide smoothly
}];
}
希望这有帮助!