美文网首页
一些常用的函数

一些常用的函数

作者: 懒得起名的伊凡 | 来源:发表于2015-09-07 14:17 被阅读120次
    类似点赞时候心跳的动画
    //.h
    #import <UIKit/UIKit.h>
    
    @interface UIView (Pop)
    
    - (void)popInsideWithDuration:(NSTimeInterval )duration;
    
    @end
    
    
    //.m
    #import "UIView+Pop.h"
    
    @implementation UIView (Pop)
    
    - (void)popDuration:(NSTimeInterval)duration
    {
        __weak typeof(self) weakSelf = self;
        self.transform = CGAffineTransformIdentity;
        // start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation
        [UIView animateKeyframesWithDuration:duration delay:0 options:0 animations:^{
            [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1/4.0 animations:^{
            typeof(self) strongSelf = weakSelf;
            strongSelf.transform = CGAffineTransformMakeScale(0.8, 0.8);
        }];
        
        [UIView addKeyframeWithRelativeStartTime:1/4.0 relativeDuration:1/2.0 animations:^{
            typeof(self) strongSelf = weakSelf;
            strongSelf.transform = CGAffineTransformMakeScale(1.2, 1.2);
        }];
        
        [UIView addKeyframeWithRelativeStartTime:3/4.0 relativeDuration:1/4.0 animations:^{
            typeof(self) strongSelf = weakSelf;
            strongSelf.transform = CGAffineTransformMakeScale(1.0, 1.0);
        }];
    } completion:^(BOOL finished) {
        
    }];
    }
    
    @end
    
    获取设备的IP地址

    需引入头文件
    #import <ifaddrs.h>
    #import <arpa/inet.h>

    方法,返回值为IP
    - (NSString *)getIPAddress
    {
    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    // retrieve the current interfaces - returns 0 on success
    success = getifaddrs(&interfaces);
    if (success == 0) {
    // Loop through linked list of interfaces
    temp_addr = interfaces;
    while(temp_addr != NULL) {
    if(temp_addr->ifa_addr->sa_family == AF_INET) {
    // Check if interface is en0 which is the wifi connection on the iPhone
    if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
    // Get NSString from C String
    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
    }
    }
    temp_addr = temp_addr->ifa_next;
    }
    }
    // Free memory
    freeifaddrs(interfaces);
    return address;
    }

    这儿可以找到

    通过十六进制的字符串返回UIColor对象

    方式一

    /*!
     * @method 通过16进制计算颜色
     * @result 颜色对象
     */
    - (UIColor *)colorFromHexRGB:(NSString *)inColorString
    {
    UIColor *result = nil;
    unsigned int colorCode = 0;
    unsigned char redByte, greenByte, blueByte;
    
    if (nil != inColorString)
    {
        NSScanner *scanner = [NSScanner scannerWithString:inColorString];
        (void) [scanner scanHexInt:&colorCode]; // ignore error
    }
    redByte = (unsigned char) (colorCode >> 16);
    greenByte = (unsigned char) (colorCode >> 8);
    blueByte = (unsigned char) (colorCode); // masks off high bits
    result = [UIColor
              colorWithRed: (float)redByte / 0xff
              green: (float)greenByte/ 0xff
              blue: (float)blueByte / 0xff
              alpha:1.0];
    return result;
    }
    

    方式二
    #define UIColorFromHexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]//UIColorFromHexRGB(0X4BAFF3)

    相关文章

      网友评论

          本文标题:一些常用的函数

          本文链接:https://www.haomeiwen.com/subject/dhdycttx.html