-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set animation speed for all windows (#1279)
* Set animation speed for all windows * remove nslog * rename * rename * Swizzle init * change testing code back * set project level
- Loading branch information
1 parent
fafb26b
commit 4081d3f
Showing
6 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// NSObject+KIFSwizzle.h | ||
// KIF | ||
// | ||
// Created by Steve Sun on 2023-04-03. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSObject (KIFSwizzle) | ||
|
||
+ (void)swizzleSEL:(SEL)originalSEL withSEL:(SEL)swizzledSEL; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// NSObject+KIFSwizzle.m | ||
// KIF | ||
// | ||
// Created by Steve Sun on 2023-04-03. | ||
// | ||
|
||
#import "NSObject+KIFSwizzle.h" | ||
#import <objc/runtime.h> | ||
|
||
@implementation NSObject (KIFSwizzle) | ||
|
||
+ (void)swizzleSEL:(SEL)originalSEL withSEL:(SEL)swizzledSEL | ||
{ | ||
Class class = [self class]; | ||
|
||
Method originalMethod = class_getInstanceMethod(class, originalSEL); | ||
Method swizzledMethod = class_getInstanceMethod(class, swizzledSEL); | ||
|
||
method_exchangeImplementations(originalMethod, swizzledMethod); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// UIWindow+KIFAdditions.h | ||
// KIF | ||
// | ||
// Created by Steve Sun on 2023-04-02. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIWindow (KIFSwizzle) | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// UIWindow+KIFAdditions.m | ||
// KIF | ||
// | ||
// Created by Steve Sun on 2023-04-02. | ||
// | ||
|
||
#import "UIWindow+KIFSwizzle.h" | ||
#import "UIApplication-KIFAdditions.h" | ||
#import "NSObject+KIFSwizzle.h" | ||
|
||
@implementation UIWindow (KIFSwizzle) | ||
|
||
+ (void)load | ||
{ | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
[self swizzleSEL:@selector(init) withSEL:@selector(swizzle_init)]; | ||
[self swizzleSEL:@selector(becomeKeyWindow) withSEL:@selector(swizzle_becomeKeyWindow)]; | ||
if (@available(iOS 13.0, *)) { | ||
[self swizzleSEL:@selector(initWithWindowScene:) withSEL:@selector(swizzle_initWithWindowScene:)]; | ||
} | ||
}); | ||
} | ||
|
||
- (instancetype)swizzle_initWithWindowScene:(UIWindowScene *)scene API_AVAILABLE(ios(13)) | ||
{ | ||
UIWindow *window = [self swizzle_initWithWindowScene:scene]; | ||
window.layer.speed = [UIApplication sharedApplication].animationSpeed; | ||
|
||
return window; | ||
} | ||
|
||
- (instancetype)swizzle_init | ||
{ | ||
UIWindow *window = [self swizzle_init]; | ||
window.layer.speed = [UIApplication sharedApplication].animationSpeed; | ||
|
||
return window; | ||
} | ||
|
||
- (void)swizzle_becomeKeyWindow | ||
{ | ||
[self swizzle_becomeKeyWindow]; | ||
self.layer.speed = [UIApplication sharedApplication].animationSpeed; | ||
} | ||
|
||
@end |