大佬教程收集整理的这篇文章主要介绍了ios – 自定义警报视图导致iPad旋转时崩溃,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我使用标准的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
以上是大佬教程为你收集整理的ios – 自定义警报视图导致iPad旋转时崩溃全部内容,希望文章能够帮你解决ios – 自定义警报视图导致iPad旋转时崩溃所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。