一些常用的函數(shù)

類似點贊時候心跳的動畫
//.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
獲取設(shè)備的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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容