UIView的animation和内存释放
来源:互联网 发布:截取动态图片软件 编辑:程序博客网 时间:2024/06/05 06:03
// 日历视图弹出
- (void)slideInCalView:(UITextField *)textField
{
if (_calView==nil) {
_calView = [[XYCalendarView alloc] initWithFrame:self.view.bounds andSelectedDate:[NSDate date] bottomBar:YES];
// _calView = [[XYCalendarView alloc] initComplexGridWithFrame:self.view.bounds andSelectedDate:[NSDate date] bottomBar:YES];
_calView.delegate = self;
}
_calView.frame=self.view.bounds;
[self.view addSubview:_calView];
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
_calView.frame = CGRectMake(0, 0, _calView.frame.size.width, _calView.frame.size.height);
} completion:^(BOOL finished) {
}];
}
//// 日历视图关闭 使用delegate method
- (void)slideOutCalendarView:(XYCalendarDay *)selectedTileDay
{
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
_calView.frame = CGRectMake(0, _calView.frame.size.height, _calView.frame.size.width, _calView.frame.size.height);
} completion:^(BOOL finished) {
[_calView removeFromSuperview];
}];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd"];
NSString *strDate = [dateFormatter stringFromDate:selectedTileDay.calDate];
// GTMLoggerDebug(@"selectedTileDate is %@", strDate);
_editingTextField.text=strDate;
_calView=nil;
}
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
_calView.frame = CGRectMake(0, _calView.frame.size.height, _calView.frame.size.width, _calView.frame.size.height);
} completion:^(BOOL finished) {
[_calView removeFromSuperview];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd"];
NSString *strDate = [dateFormatter stringFromDate:selectedTileDay.calDate];
// GTMLoggerDebug(@"selectedTileDate is %@", strDate);
_editingTextField.text=strDate;
_calView=nil;
}];
奇怪的一点是,释放内存的代码是removeFromSuperview 而不是nil.
不对,还是nil释放内存,只是没有remove掉,表示还有对象在使用它,所以nil时不释放内存。
这里是没有remove掉,那么nil也不会成功。
subview设置为nil后,却没有removefromsuperview,那么占有的内存还在。这就导致来内存泄漏。
非常隐蔽的内存泄漏。
正确的方式是:
先remove后nil才是正确的是否内存的方式。如果还向对象继续留在内存里,下次调用不用定义,这在 主视图退出时nil。
- UIView的animation和内存释放
- uiview的animation动画
- 使用UIView的animation
- UIView的动画 Animation
- 内存的申请和释放
- UIView类的UIViewAnimationWithBlocks扩展 和 使用core animation
- UIView Animation的一些用法
- UIView的Animation相关函数
- UIView Animation的一些用法
- UIView Animation 的参数详解
- UIView Animation的一些用法
- 如何停止UIView的animation
- uiview animation
- UIView(animation)
- UIView Animation
- 变量的内存分配和释放
- 分配和释放 BSTR 的内存
- 分配和释放 BSTR 的内存
- 眼前这道坎一定会迈过去
- TCP心跳机制
- 顺序查找
- 折半查找
- ViewCache的理解
- UIView的animation和内存释放
- oracle update+with语法
- 好的IT学习网站(不断更新)
- ORA-12547: TNS:lost contact
- nyist-733-万圣节派对
- A20成功驱动FT5206触摸屏
- FPGA中FIFO的配置
- 黑马程序员_类加载器
- Java 中的悲观锁和乐观锁的实现