如果我在这两者之间切换数百次会发生什么?将留下未使用的UIView
s的汉德? 我在主UIView
上有几个控件,我想多次将它们作为一组控件进行动画(向上滑动和向下滑动),然后我决定将它们添加到UIView
并为该视图添加动画。但似乎每次当我将view
添加到superView
时,它仍然存在,如果我运行[view removeFromSuperView]
,它还会删除我已添加到view
的所有控件。它会影响性能还是会导致内存泄漏问题?移除动画后的UIView,而不会丢失其他元素
(void)slideUp{
repeatViewTop = datePickerButton.frame.origin.y;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, repeatViewTop)];
[view addSubview:taskTitle];
[view addSubview:taskNote];
[view addSubview:datePickerButton];
[view addSubview:taskSelectedDateViewer];
[self.view addSubview:view];
[UIView animateWithDuration:0.4f
delay:0.1f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
float tempY=view.frame.origin.y;
[view setCenter:CGPointMake(SCREEN_WIDTH/2,tempY)];
[view setAlpha:0.4f];
}
completion:^(BOOL finished){
}];
[self.view insertSubview:view atIndex:0];
}
这会滑下这些控件:
- (void)slideDown{
taskTitle.userInteractionEnabled=NO;
//150=view.frame.origin.y after sliding up
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -114, SCREEN_WIDTH, repeatViewTop)];
[view addSubview:taskTitle];
[view addSubview:taskNote];
[view addSubview:datePickerButton];
[view addSubview:taskSelectedDateViewer];
[self.view addSubview:view];
[UIView animateWithDuration:0.4f
delay:0.1f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
float tempY=view.frame.origin.y *(-1);
[view setCenter:CGPointMake(SCREEN_WIDTH/2,tempY)];
[view setAlpha:1.0f];
}
completion:^(BOOL finished){
}];
[self.view insertSubview:view atIndex:0];
}
你应该只在一次视图**中添加元素**,并保持对视图的引用,然后对其进行动画处理,而不是一直插入。 – Lefteris
@Lefteris如何做到这一点?我是iOS编程新手 – Maysam
'@property(strong,nonatomic)UIView * viewA'并初始化一次,然后作为子视图添加到'viewDidLoad'方法中。 –