2013-07-24 3 views
0

Мне нужно реализовать анимацию, которая действует, когда объект удален из прокрутки.Заполнить анимацию пустой области при удалении объекта?

Например, в прокрутке есть 5 объектов (Вид). Когда объект объекта удален, другой будет перемещаться рядом с другим с анимацией. то есть, когда третий удаляется, четвертый и пятый подойдут к второму, и он будет выглядеть как прокрутка, содержащая четыре объекта.

Как я могу достичь этого требования?

Любая идея?

self.frame = CGRectMake(0, 0, 1024, 768); 



    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    deleteButton.frame = CGRectMake(0, 0, 100, 100); 
    [deleteButton setTitle:@"fuck" forState:UIControlStateNormal]; 
    [deleteButton addTarget:self action:@selector(removeViews) forControlEvents:UIControlEventTouchUpInside]; 

    [self addSubview:deleteButton]; 




    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 200, 800, 100)]; 
    [scrollView setScrollEnabled:YES]; 
    scrollView.pagingEnabled = YES; 
    [scrollView setDelegate:self]; 
    scrollView.backgroundColor = [UIColor brownColor]; 
    [scrollView setShowsHorizontalScrollIndicator:YES]; 
    [scrollView setIndicatorStyle:UIScrollViewIndicatorStyleDefault]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    scrollView.contentMode = UIViewContentModeScaleToFill; 
    [scrollView setContentSize:CGSizeMake(1000,100)]; 


    [self setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]]; 


    int countViews = 6; 

    //for each number add one circleview to your scrollview. for each circleview add a button, to remove the view from the scrollview 
    for(int i=0;i<countViews;i++){ 




     UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(100+(i*100),5,90,90)]; 
     circleView.backgroundColor = [UIColor whiteColor]; 
     circleView.tag = i; 
     [scrollView addSubview:circleView]; 

     UILabel* circleIndex = [[UILabel alloc] init]; 
     circleIndex.frame = CGRectMake(30, 25, 40, 40); 
     [circleIndex setFont:[UIFont fontWithName:@"Arial-BoldMT" size:40]]; 
     [circleIndex setText:[NSString stringWithFormat:@"%d",i]]; 

     [circleView addSubview:circleIndex];     

     UIView *exitView = [[UIView alloc] initWithFrame:CGRectMake(70,-5,30,30)]; 
     exitView.layer.cornerRadius = 15; 
     exitView.backgroundColor = [UIColor redColor]; 
     exitView.layer.borderColor = [[UIColor whiteColor] CGColor]; 
     exitView.layer.borderWidth = 2; 

     exitView.tag = i; 


     [exitView setHidden:YES]; 
     [circleView addSubview:exitView]; 




     UIView *exitLabel = [[UIView alloc] initWithFrame:CGRectMake(8,13,15,3)]; 
     exitLabel.backgroundColor = [UIColor clearColor]; 
     exitLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; 
     exitLabel.layer.borderWidth = 2; 

     [exitView addSubview:exitLabel]; 


     UILongPressGestureRecognizer *longPress = 
     [[UILongPressGestureRecognizer alloc] initWithTarget:self 
                 action:@selector(handleLongPress:)]; 
     [circleView addGestureRecognizer:longPress]; 

     UITapGestureRecognizer *singlePress = 
     [[UITapGestureRecognizer alloc] initWithTarget:self 
               action:@selector(handleSinglePress:)]; 
     [exitView addGestureRecognizer:singlePress]; 

    } 




//[circleView bringSubviewToFront:exitView]; 


    [self addSubview:scrollView]; 



} 
return self; 
} 


-(void)removeViews:(id)sender{ 


[[scrollView viewWithTag:[sender tag]] removeFromSuperview]; 
[[scrollView viewWithTag:([sender tag]-100)] removeFromSuperview]; 

//[scrollView setNeedsDisplay]; 

//[self setNeedsDisplay]; 

NSLog(@"%d",scrollView.subviews.count); 


for(int i=0; i<(scrollView.subviews.count/2-[sender tag]+1);i++) 
{ 

[UIView animateWithDuration:0.5f 
         delay:0.0f 
        options:UIViewAnimationOptionBeginFromCurrentState 
       animations:^{ 
        [[scrollView viewWithTag:([sender tag]+i)] setFrame:CGRectMake(100+(i*100),5,90,90)]; // last position 
       } 
       completion:nil]; 

} 


     } 
} 


//The event handling method 
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer{ 
//CGPoint location = [recognizer locationInView:[recognizer.view superview]]; 
if (recognizer.state == UIGestureRecognizerStateEnded) { 

    [self shakeView:recognizer.view]; 
    [[recognizer.view viewWithTag:2] setHidden:NO]; 
} 
} 

- (void)handleSinglePress:(UITapGestureRecognizer *)recognizer{ 
//CGPoint location = [recognizer locationInView:[recognizer.view superview]]; 
if (recognizer.state == UIGestureRecognizerStateEnded) { 

    [self removeViews:[recognizer.view viewWithTag:4]]; 

} 
} 

- (void)singlePress:(UITapGestureRecognizer *)recognizer{ 
//CGPoint location = [recognizer locationInView:[recognizer.view superview]]; 
if (recognizer.state == UIGestureRecognizerStateEnded) { 

    [recognizer.view.layer removeAllAnimations]; 

    //[exitView setHidden:YES]; 
} 
} 

ответ

0

при удалении объекта и нужно вызвать [scrollview setneedsDisplay] обновить Scrollview

+0

я пытался, но никакого эффекта – erdemgc

+0

вы также должны установить рамку с этим –

+0

я это сделал, до сих пор нет эффекта. другой интересный момент, только первый вид прокрутки может быть удален, другие не могут быть такими – erdemgc

Смежные вопросы