主播卡片头像跳转、左右震动动画

This commit is contained in:
chenguilong
2022-08-03 16:51:06 +08:00
parent 8c637aaafd
commit 4325a9aa3c
3 changed files with 65 additions and 3 deletions

View File

@@ -59,6 +59,7 @@
#import "XPNewUserRechargeSucessView.h"
#import "XPTaskCompleteTipView.h"
#import "XPWebViewController.h"
#import "XPMineUserInfoViewController.h"
///Present
#import "MainPresenter.h"
#import "MainProtocol.h"
@@ -143,7 +144,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[self.selectedViewController.navigationController presentViewController:vc animated:YES completion:nil];
}
if (self.needShowAnchorCard && !self.delayShowAnchorCard) {
[self.presenter getAnchorCardInfo];;
[self.presenter getAnchorCardInfo];
}
if (self.secondLaunchShowAnchorCard) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -257,6 +258,10 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
[UIView animateWithDuration:0.5 animations:^{
self.anchorCardView.frame = CGRectMake(0, kStatusBarHeight, KScreenWidth, 90);
} completion:^(BOOL finished) {
if (finished) {
[self shakeAction];
}
}];
self.anchorCardView.cardInfo = cardInfo;
[self.view addSubview:self.anchorCardView];
@@ -266,6 +271,36 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
}
}
///
- (void)shakeAction {
//
static int numberOfShakes = 4;
//
static float vigourOfShake = 0.04f;
//
static float durationOfShake = 0.5f;
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//
CGPoint layerPosition = self.anchorCardView.layer.position;
//
NSValue *value1 = [NSValue valueWithCGPoint:self.anchorCardView.layer.position];
//
NSMutableArray *values = [[NSMutableArray alloc] initWithObjects:value1, nil];
for (int i = 0; i<numberOfShakes; i++) {
//
NSValue *valueLeft = [NSValue valueWithCGPoint:CGPointMake(layerPosition.x-self.anchorCardView.frame.size.width*vigourOfShake*(1-(float)i/numberOfShakes), layerPosition.y)];
NSValue *valueRight = [NSValue valueWithCGPoint:CGPointMake(layerPosition.x+self.anchorCardView.frame.size.width*vigourOfShake*(1-(float)i/numberOfShakes), layerPosition.y)];
[values addObject:valueLeft];
[values addObject:valueRight];
}
//
[values addObject:value1];
shakeAnimation.values = values;
shakeAnimation.duration = durationOfShake;
[self.anchorCardView.layer addAnimation:shakeAnimation forKey:kCATransition];
}
#pragma mark - NIMLoginManagerDelegate
- (void)onAutoLoginFailed:(NSError *)error {
// autoLogin 417
@@ -589,9 +624,23 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
}
}
- (void)xPAnchorCardViewClickAvatar:(NSString *)uid {
if (uid.length) {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = uid.integerValue;
[self.selectedViewController.navigationController pushViewController:userInfoVC animated:YES];
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
} else {
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
}
}
- (void)handleAnchorCardSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
if(recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"swipe up");
[UIView animateWithDuration:0.5 animations:^{
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
} completion:^(BOOL finished) {