iCarousel is been shown up in previous page when clicked the back button

孤街浪徒 提交于 2019-12-12 12:34:19

问题


When i press the back button. the iCarousel is still shows up for 1 second.why is this happening and how to stop this.I have used storyboard to create a iCarosel view..

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


回答1:


I actually tried to reproduce your problem and did see that the carousel view stays for a second when 'pop' or back button press happens. This particularly happens when you the carousel is swiped and then the back button pressed. As a workaround, I was able to fix it by setting the iCarousel hidden in the viewWillDisappear method.

- (void)viewWillDisappear:(BOOL)animated 
{

[YOUR_CAROUSEL_NAME setHidden:YES]; //This sets the carousel to be hidden when you press Back button

}

If this looks to be hidden suddenly, you can perhaps try setting the alpha to 0.0 inside an animation block. Something like this:

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

}

Hope this helps!




回答2:


Hiding and unhiding is not the solution. What you need is just one line:

yourCarousel.clipsToBounds = YES;


来源:https://stackoverflow.com/questions/22279297/icarousel-is-been-shown-up-in-previous-page-when-clicked-the-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!