
如果我使用标准的UIAlertVIEw,则不会发生此崩溃.我从其他人那里找到了自定义alertvIEw的代码.这里有什么错误的补充吗?或者我怎样才能获得更多有关正在发生的事情的线索?
@implementation CustomAlertVIEw- (voID) setBackgroundcolor:(UIcolor *) background withstrokecolor:(UIcolor *) stroke{ if(fillcolor != nil) { [fillcolor release]; [bordercolor release]; } fillcolor = [background retain]; bordercolor = [stroke retain];}- (ID)initWithFrame:(CGRect)frame{ if((self = [super initWithFrame:frame])) { if(fillcolor == nil) { } } return self;}- (voID)layoutSubvIEws{ for (UIVIEw *sub in [self subvIEws]) { if([sub class] == [UIImageVIEw class] && sub.tag == 0) { // The alert background UIImageVIEw tag is 0,// if you are adding your own UIImageVIEw's // make sure your Tags != 0 or this fix // will remove your UIImageVIEw's as well! [sub removeFromSupervIEw]; break; } }}- (voID)drawRect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context,rect); CGContextSetAllowsAntialiasing(context,true); CGContextSetlinewidth(context,0.0); CGContextSetAlpha(context,0.8); CGContextSetlinewidth(context,2.0); CGContextSetstrokecolorWithcolor(context,[bordercolor CGcolor]); CGContextSetFillcolorWithcolor(context,[fillcolor CGcolor]); // Draw background CGfloat backOffset = 2; CGRect backRect = CGRectMake(rect.origin.x + backOffset,rect.origin.y + backOffset,rect.size.wIDth - backOffset*2,rect.size.height - backOffset*2); [self drawRoundedRect:backRect inContext:context withRadius:8]; CGContextDrawPath(context,kCGPathFillstroke); // Clip Context CGRect clipRect = CGRectMake(backRect.origin.x + backOffset-1,backRect.origin.y + backOffset-1,backRect.size.wIDth - (backOffset-1)*2,backRect.size.height - (backOffset-1)*2); [self drawRoundedRect:clipRect inContext:context withRadius:8]; CGContextClip (context); //Draw highlight CGGradIEntRef glossGradIEnt; CGcolorSpaceRef rgbcolorspace; size_t num_locations = 2; CGfloat locations[2] = { 0.0,1.0 }; CGfloat components[8] = { 1.0,1.0,0.35,0.06 }; rgbcolorspace = CGcolorSpaceCreateDeviceRGB(); glossGradIEnt = CGGradIEntCreateWithcolorComponents(rgbcolorspace,components,locations,num_locations); CGRect ovalRect = CGRectMake(-130,-115,(rect.size.wIDth*2),rect.size.wIDth/2); CGPoint start = CGPointMake(rect.origin.x,rect.origin.y); CGPoint end = CGPointMake(rect.origin.x,rect.size.height/5); CGContextSetAlpha(context,1.0); CGContextAddEllipseInRect(context,ovalRect); CGContextClip (context); CGContextDrawlinearGradIEnt(context,glossGradIEnt,start,end,0); CGGradIEntRelease(glossGradIEnt); CGcolorSpaceRelease(rgbcolorspace); }- (voID) drawRoundedRect:(CGRect) rrect inContext:(CGContextRef) context withRadius:(CGfloat) radius{ CGContextBeginPath (context); CGfloat minx = CGRectGetMinX(rrect),mIDx = CGRectGetMIDX(rrect),maxx = CGRectGetMaxX(rrect); CGfloat miny = CGRectGetMinY(rrect),mIDy = CGRectGetMIDY(rrect),maxy = CGRectGetMaxY(rrect); CGContextMovetoPoint(context,minx,mIDy); CGContextAddArctopoint(context,miny,mIDx,radius); CGContextAddArctopoint(context,maxx,mIDy,maxy,radius); CGContextClosePath(context);}- (voID)DisabledismissForIndex:(int)index_{ canIndex = index_; Disabledismiss = TRUE;}- (voID)dismissAlert{ [self dismissWithClickedbuttonIndex:[self cancelbuttonIndex] animated:YES];}- (voID)vibratealert:(float)seconds{ canVirate = TRUE; [self moveleft]; [self performSelector:@selector (stopVibration) withObject:nil afterDelay:seconds];}-(voID)dismissWithClickedbuttonIndex:(NSInteger)buttonIndex animated:(BOol)animated { if (Disabledismiss == TRUE && canIndex == buttonIndex){ }else { [super dismissWithClickedbuttonIndex:buttonIndex animated:animated]; }}- (voID)hIDeAfter:(float)seconds{ [self performSelector:@selector (dismissAlert) withObject:nil afterDelay:seconds];}- (voID)moveRight{ if (canVirate){ [UIVIEw beginAnimations:nil context:NulL]; [UIVIEw setAnimationDuration:0.05]; self.transform = CGAffinetransformMakeTranslation(-10.0,0.0); [UIVIEw commitAnimations]; [self performSelector:@selector (moveleft) withObject:nil afterDelay:0.05]; }}- (voID)moveleft{ if (canVirate){ [UIVIEw beginAnimations:nil context:NulL]; [UIVIEw setAnimationDuration:0.05]; self.transform = CGAffinetransformMakeTranslation(10.0,0.0); [UIVIEw commitAnimations]; [self performSelector:@selector (moveRight) withObject:nil afterDelay:0.05]; }}- (voID)stopVibration{ canVirate = FALSE; self.transform = CGAffinetransformMakeTranslation(0.0,0.0);}@end解决方法 好的,现在我找到了.在layoutVIEws方法中,替换[sub removeFromSupervIEw]; line(((UIImageVIEw *)sub).image = nil;为我解决了这个问题.尽管如此,我仍然不确定原因. 总结 以上是内存溢出为你收集整理的ios – 自定义警报视图导致iPad旋转时崩溃全部内容,希望文章能够帮你解决ios – 自定义警报视图导致iPad旋转时崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)