分类格式:
@interface 待扩展的类(分类的名称)
@end
@implementation 待扩展的名称(分类的名称)
@end
实际具体示例:
// Programmer+Category.h文件中
@interface Programmer (Category)
@property(nonatomic,copy) NSString *nameWithSetterGetter; //设置setter/getter方法的属性
@property(nonatomic,copy) NSString *nameWithoutSetterGetter; //不设置setter/getter方法的属性(注意是可以写在这,而且编译只会报警告,运行不报错)
- (void) programCategoryMethod; //分类方法
@end
// Programmer+Category.m文件中
UINavigationController分类:push、pop各种样式
使用方法:
WKWebViewController *userAgreementVC = [[WKWebViewController alloc] init];
[userAgreementVC loadWebURLSring:@"https://resource.weatherat.com.html"];
userAgreementVC.titleStr = @"隐私政策";
[self.navigationController pushViewController:userAgreementVC withCATransitionType:JYPCCATransitionTypePush subType:JYPCCATransitionSubTypeFromRight animated:NO];
UINavigationController+CATransition.h:
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, JYPCCATransitionType) {
JYPCCATransitionTypeFade = 1, // 淡化
JYPCCATransitionTypeMoveIn, // 覆盖
JYPCCATransitionTypePush, // push
JYPCCATransitionTypeReveal, // 揭开
JYPCCATransitionTypeCube, // 3D立方
JYPCCATransitionTypeSuckEffect, // 吮吸
JYPCCATransitionTypeOglFlip, // 翻转
JYPCCATransitionTypeRippleEffect, // 波纹
JYPCCATransitionTypePageCurl, // 翻页
JYPCCATransitionTypePageUnCurl, // 反翻页
JYPCCATransitionTypeCameraIrisHollowOpen, // 开镜头
JYPCCATransitionTypeCameraIrisHollowClose, // 关镜头
};
typedef NS_ENUM(NSInteger, JYPCCATransitionSubType) {
JYPCCATransitionSubTypeFromRight = 1,
JYPCCATransitionSubTypeFromLeft,
JYPCCATransitionSubTypeFromTop,
JYPCCATransitionSubTypeFromBottom
};
@interface UINavigationController (CATransition)
// 传枚举
// push
- (void)pushViewController:(UIViewController *)viewController withCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated;
// pop
- (void)popViewControllerWithCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated;
// 传字符串
// push
- (void)pushViewController:(UIViewController *)viewController withCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated;
// pop
- (void)popViewControllerWithCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated;
// pop根目录
- (void)popRootViewControllerWithCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated;
- (void)popRootViewControllerWithCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated;
@end
UINavigationController+CATransition.m:
#import "UINavigationController+CATransition.h"
#define kTransitionDuration 0.5
@implementation UINavigationController (CATransition)
- (void)pushViewController:(UIViewController *)viewController withCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated
{
CATransition *transition = [CATransition animation];
transition.duration = kTransitionDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = typeString;
transition.subtype = subTypeString;
[self.view.layer addAnimation:transition forKey:@"animation"];
[self pushViewController:viewController animated:animated];
}
- (void)popViewControllerWithCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated
{
CATransition *transition = [CATransition animation];
transition.duration = kTransitionDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = typeString;
transition.subtype = subTypeString;
[self.view.layer addAnimation:transition forKey:@"animation"];
[self popViewControllerAnimated:animated];
}
- (void)popRootViewControllerWithCATransitionTypeString:(NSString *)typeString subTypeString:(NSString *)subTypeString animated:(BOOL)animated
{
CATransition *transition = [CATransition animation];
transition.duration = kTransitionDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = typeString;
transition.subtype = subTypeString;
[self.view.layer addAnimation:transition forKey:@"animation"];
[self popToRootViewControllerAnimated:animated];
}
- (void)pushViewController:(UIViewController *)viewController withCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated
{
NSString *typeString = [self getCATransitionTypeStringWithCATransitionType:type];
NSString *subTypeString = [self getCATransitionSubType:subType];
[self pushViewController:viewController withCATransitionTypeString:typeString subTypeString:subTypeString animated:animated];
}
- (void)popRootViewControllerWithCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated
{
NSString *typeString = [self getCATransitionTypeStringWithCATransitionType:type];
NSString *subTypeString = [self getCATransitionSubType:subType];
[self popRootViewControllerWithCATransitionTypeString:typeString subTypeString:subTypeString animated:animated];
}
- (void)popViewControllerWithCATransitionType:(JYPCCATransitionType)type subType:(JYPCCATransitionSubType)subType animated:(BOOL)animated
{
NSString *typeString = [self getCATransitionTypeStringWithCATransitionType:type];
NSString *subTypeString = [self getCATransitionSubType:subType];
[self popViewControllerWithCATransitionTypeString:typeString subTypeString:subTypeString animated:animated];
}
- (NSString *)getCATransitionSubType:(JYPCCATransitionSubType) subType{
switch (subType) {
case JYPCCATransitionSubTypeFromRight:
return kCATransitionFromRight;
break;
case JYPCCATransitionSubTypeFromLeft:
return kCATransitionFromLeft;
break;
case JYPCCATransitionSubTypeFromTop:
return kCATransitionFromTop;
break;
case JYPCCATransitionSubTypeFromBottom:
return kCATransitionFromBottom;
break;
default:
return @"";
break;
}
}
- (NSString *)getCATransitionTypeStringWithCATransitionType:(JYPCCATransitionType)type{
switch (type) {
case JYPCCATransitionTypeFade:
return kCATransitionFade; // 淡化
break;
case JYPCCATransitionTypeMoveIn:
return kCATransitionMoveIn; // 覆盖
break;
case JYPCCATransitionTypePush:
return kCATransitionPush; // push
break;
case JYPCCATransitionTypeReveal:
return kCATransitionReveal; // 揭开
break;
case JYPCCATransitionTypeCube:
return @"cube"; // 3D立方
break;
case JYPCCATransitionTypeSuckEffect:
return @"suckEffect"; // 吮吸
break;
case JYPCCATransitionTypeOglFlip:
return @"oglFlip"; // 翻转
break;
case JYPCCATransitionTypeRippleEffect:
return @"rippleEffect"; // 波纹
break;
case JYPCCATransitionTypePageCurl:
return @"pageCurl"; // 翻页
break;
case JYPCCATransitionTypePageUnCurl:
return @"pageUnCurl"; // 反翻页
break;
case JYPCCATransitionTypeCameraIrisHollowOpen:
return @"cameraIrisHollowOpen"; // 开镜头
break;
case JYPCCATransitionTypeCameraIrisHollowClose:
return @"cameraIrisHollowClose"; // 关镜头
break;
default:
return @"";
break;
}
}
@end
网友评论