我正在和UIView合作.我想在那个视图上做动画.点击视图时,应将其分为两部分并向两侧移动.请帮我解决一个问题.
解决方法
@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.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
尝试创建这样的UIView类.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。