hello_vzjw

iOS 开发中遇到的一个小问题

1、修改当前视图的透明度,而不影响子视图的透明度

self.backgroundColor = [[UIColorwhiteColor] colorWithAlphaComponent:0];

2、push之前将自己移除掉,使view返回时直接返回到父类

ExamineeSelectSubjectController * examineepersonal = [ExamineeSelectSubjectControllerloadFromNib:dic];

[examineepersonal setHidesBottomBarWhenPushed:YES];

NSMutableArray * array =[[NSMutableArrayalloc]initWithArray:self.navigationController.viewControllers];

    //删除最后一个,也就是自己

    [array removeObjectAtIndex:array.count-1];

    //添加要跳转的controller

    [array addObject:examineepersonal];

    [self.navigationControllersetViewControllers:array animated:YES];

 

3、返回按钮为中文字,且字体会在最左边:

UIBarButtonItem * backItem = [[UIBarButtonItem alloc] init];

[backItem setTitle:@“返回”];

self.navigationItem.backBarButtonItem = backItem;

 

4、写了-(void)viewDidLoad{}就不要写-(void)aweakfromNib{ }

 

5、写上以下代码就可以让view controller的起始点自然在navigation bar下面:

if([self respondsToSelector:@selector(edgesExtenedLayout)]){

self.edgesForExtendedLayout = UIRectEdgeNone

}

 

6、给textField加左边的view

[self addLeftViewToTextField:_emailTF];

-(void)addLeftViewToTextField:(UITextField *)textField{

CGrect frameLeft = [textField frame];

frameLeft.size.width = 10;

UIView * leftView = [[UIView alloc] initWithFrame:frameLeft];

[textField setLeftViewMode:UITextFieldViewModeAlways];

[textField setLeftView:leftView];

}

 

7、post数据json解析:

NSDictionary * retDic = [NSJSONSerialization JSONObjectWithData:operation.responseData options:NSJSONReadingMutableContainers error:nil];

 

8HUD显示的方法:

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:this animated:YES];

hud.mode = MBProgressHUDModeText;

            hud.labelText = @"发送失败";

            hud.margin = 10.f;

            hud.yOffset = 150.f;

            hud.removeFromSuperViewOnHide = YES;

            [hud hide:YESafterDelay:0.5];

 

9、将图片保存到沙盒目录里:

 

[selfsaveImage:image withName:@"avarter_tmp.jpg"];

- (void) saveImage:(UIImage *)image withName:(NSString *)name {

    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);

    NSString *imagePath = [selfwriteImage:imageData withName:name];

}

 

- (NSString *) writeImage:(NSData *)imageData withName:(NSString *)name {

    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:name];

    [imageData writeToFile:fullPath atomically:YES];

    return fullPath;

}

 

10、cell点击之后闪一下:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

 

11、loadFromNib函数

+ (id)loadFromNib:(NSMutableDictionary *)_extraParams {

    

    NSArray* arrayNib = [[NSBundlemainBundle] loadNibNamed:@"KCShareViewController"owner:selfoptions:nil];

    return [arrayNib objectAtIndex:0];

}

 

12、友盟分享:

qq的URLScheme必须要转换为16机制。不然会出现很多问题。

 

13、给字符串加一条横线(富文本编辑)

 NSMutableAttributedString * testAttriString = [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@“¥%@“,@“test”]];

            [testAttriString addAttribute:NSStrikethroughStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, testAttriString.length)];

            _dayLabel.attributedText = testAttriString;

 

14、计算某一条字符串的size

CGSize size = [_MoneyLabel.textsizeWithFont:[UIFontsystemFontOfSize:17] constrainedToSize:CGSizeMake(MAXFLOAT, 23)];

 

15、让UIImageView里的图片加载完之后在过渡透明度显示图片

[_courseImagesd_setImageWithURL:[NSURLURLWithString:courseModel.picture] placeholderImage:[UIImagedrawPlaceholderImage:_courseImage.sizecolorRGB:courseModel.picture_color] options:0completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        this.courseImage.alpha = 0.0;

        [UIViewanimateWithDuration:0.3animations:^{

            this.courseImage.alpha = 1.0;

        }];

        

    }];

 

15、cell上的倒计时

1)、首先、每cell上都有一个NSTimer在进行倒计时。

 

-(void)startTimer:(NSString *)str

{

    _strId = str;

    [_timerinvalidate];

    _timer = nil;

    _timer = [NSTimerscheduledTimerWithTimeInterval:1

                                              target:selfselector:@selector(refreshTime)

                                            userInfo:nilrepeats:YES];

    [[NSRunLoopcurrentRunLoop] addTimer:_timerforMode:UITrackingRunLoopMode];

}

 

-(void)refreshTime

{

    if ([self.delegaterespondsToSelector:@selector(timeCountDownCell: withtvid:)]) {

        [self.delegatetimeCountDownCell:selfwithtvid:_strId];

//这里的代理方法是对UI上的显示进行更新。

    }

}

2)、其次,在controller里对model里的时间进行倒计时。

-(void)allCourseInfomodelTimeCountdown

{

    [_timerinvalidate];

    _timer = nil;

    _timer= [NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(counttimedown) userInfo:nilrepeats:YES];

    [[NSRunLoopcurrentRunLoop] addTimer:_timerforMode:UITrackingRunLoopMode];

}

 

-(void)counttimedown

{

    if (self.courseLists.count!=0) {

        for (int i=0; i<self.courseLists.count; i++) {

            CourseInfo * model = [self.courseListsobjectAtIndex:i];

            if (model.discount_timelimit&&[model.discount_timelimitintegerValue]!=0) {

                model.discount_timelimit =[NSNumbernumberWithInt:([model.discount_timelimitintValue]-1)];

            }

        }

    }

}

3)、实现UI更新的代理方法

-(void)timeCountDownCell:(CourseCell *)cell withtvid:(NSString *)strId

{

}

 

 

16、CHDViewController这个是左右滚动的三方库

 

17、ZHPickView这个是选择器的三方库

 

18、获取到手势点击的位置而触发不同的函数

-(void)SingleTap:(UIGestureRecognizer *)gestureRecognizer

{

    CGPoint point = [gestureRecognizer locationInView:self.tableview];

    NSIndexPath *indexPath = [self.tableviewindexPathForRowAtPoint:point];

    

    // Get the whole rect for section.

    CGRect sectionRect = [self.tableviewrectForSection:[indexPath section]];

    

    // Get the rect of the section header in specified section.

    CGRect sectionHeaderRect = [self.tableviewrectForHeaderInSection:[indexPath section]];

    

    // Calculate the actual rect for all cells.

    CGRect croppedRect = CGRectMake(sectionRect.origin.x, sectionRect.origin.y+sectionHeaderRect.size.height, sectionRect.size.width, sectionRect.size.height-sectionHeaderRect.size.height);

    

    if (CGRectContainsPoint(croppedRect, point)) {

        // If we tapped at cell part.

        if ([indexPath section] != 3) {

            [self.audioviewremoveCurrentView];

            self.tableviewspacetobottom.constant = 0;

            [selftableView:self.tableviewdidSelectRowAtIndexPath:indexPath];

        } else {

            [selftableView:self.tableviewdidSelectRowAtIndexPath:indexPath];

        }

    } else {

        // if we tapped at section header, we will not do the select.

        [self.audioviewremoveCurrentView];

        self.tableviewspacetobottom.constant = 0;

    }

}

 

 

19、//将图片固定像素

- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size

{

    UIGraphicsBeginImageContext(size);

    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;

}


 

 

posted on 2015-12-28 11:13  hello_vzjw  阅读(154)  评论(0)    收藏  举报

导航