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

一些常用的函数

作者: 懒得起名的伊凡 | 来源:发表于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)

相关文章

  • GCD之semaphore函数

    GCD中, 有一些函数很常用, 比如同步函数, 异步函数, 障碍函数, 一次性函数等; 另外一些不太常用, 如迭代...

  • XPath 用法总结

    xpath常用方法 常用定位元素的方法 一些常用函数

  • SQL-1

    查询 选择查询 数值计算 常用聚合函数 sum,avg, 还有一些常用的函数 COUNT() 计数 FIRST()...

  • iOS中的一些数学函数

    一些常用的函数 Math Functions(数学函数) lgammaf 数值计算函数 truncf截断函数 转载...

  • python学习2

    python学习二 一些常用函数

  • php-常用函数

    常用函数 常用函数: 数组常用函数

  • Objective-C中的数学函数math.h

    数学函数库,一些数学计算的公式的具体实现是放在math.h里,具体有: 常用函数: 数学常量: 常用函数: iOS...

  • 一些常用的函数

    类似点赞时候心跳的动画 获取设备的IP地址 需引入头文件#import #import 方法,返回值为IP- (...

  • 一些常用的函数

  • 一些常用函数

    range(start,stop,step)

网友评论

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

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