UIView is split into 2 parts with animation

I work with UIView. I want to make an animation from this point of view. When you click on a view, it should be divided into two parts and move in both directions. Please help me with the right solution.

+4
source share
1 answer
@implementation SplitView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code self.backgroundColor = [UIColor blueColor]; UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(split)]; [self addGestureRecognizer:ges]; [ges release]; } return self; } - (void)split { CGRect f = self.frame; CGRect f1 = CGRectMake(CGRectGetMinX(f), f.origin.y, f.size.width/2, f.size.height); CGRect f2 = CGRectMake(CGRectGetMidX(f), f.origin.y, f.size.width/2, f.size.height); SplitView *view1 = [[[SplitView alloc] initWithFrame:f1] autorelease]; [self.superview addSubview:view1]; SplitView *view2 = [[[SplitView alloc] initWithFrame:f2] autorelease]; [self.superview addSubview:view2]; f1.origin.x -= 30; f2.origin.x += 30; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; view1.frame = f1; view2.frame = f2; [UIView commitAnimations]; [self removeFromSuperview]; } @end 

Try creating such a UIView class.

+1
source

Source: https://habr.com/ru/post/1390034/


All Articles