主播卡片弹出时手机震动

This commit is contained in:
chenguilong
2022-08-04 11:42:49 +08:00
parent f3e1d3d204
commit 2da12a4e4f
3 changed files with 129 additions and 39 deletions

View File

@@ -64,8 +64,8 @@
- (void)removeFromSuperview {
[super removeFromSuperview];
[self resumeTimer];
if (self.isPlaying) {
[self resumeTimer];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
}
}

View File

@@ -10,6 +10,7 @@
#import <ReactiveObjC/ReactiveObjC.h>
#import <NIMSDK/NIMSDK.h>
#import <Masonry/Masonry.h>
#import <AudioToolbox/AudioToolbox.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
@@ -141,7 +142,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
vc.hadAnimate = YES;
[self.selectedViewController.navigationController presentViewController:vc animated:YES completion:nil];
}
if ([self hadLaunchApp] && (self.selectedIndex == 0 | self.selectedIndex == 1) && [self canShowAnchorCard]) {
if ([self hadLaunchApp] && [self canShowAnchorCard]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.view.window && self.isViewLoaded) {
[self.presenter getAnchorCardInfo];
@@ -258,11 +259,8 @@ 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];
}
}];
} completion:nil];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//
long time = (long)([[NSDate date] timeIntervalSince1970]*1000);
[[NSUserDefaults standardUserDefaults] setObject:@(time) forKey:kLastShowAnchorCardTime];
[[NSUserDefaults standardUserDefaults] synchronize];
@@ -274,36 +272,6 @@ 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

View File

@@ -20,6 +20,10 @@
#import "XCCurrentVCStackManager.h"
#import "XPMineUserInfoViewController.h"
#import "XPMineRechargeViewController.h"
///vc
#import "XPMineDressUpViewController.h"
#import "XPDressUpShopViewController.h"
#import "XPRoomViewController.h"
typedef NS_ENUM(NSUInteger, RightNavigationPushType){
///h5
@@ -83,6 +87,8 @@ NSString * const kJSGetRoomUid = @"getRoomUid";
NSString * const kOpenPersonPage = @"openPersonPage";
NSString * const kInitShowNav = @"initShowNav";
NSString * const kCloseWebView = @"closeWebView";
NSString * const kJumpAppointPage = @"jumpAppointPage";
NSString * const kJSOpenRoom = @"openRoom";
@implementation XPWebViewController
@@ -262,11 +268,124 @@ NSString * const kCloseWebView = @"closeWebView";
if (self.navigationController) {
[self.navigationController popViewControllerAnimated:YES];
}
}
} else if ([message.name isEqualToString:kJumpAppointPage]) {
// h5
NSDictionary *bodyDict;
if ([message.body isKindOfClass:[NSDictionary class]]) {
bodyDict = message.body;
} else if ([message.body isKindOfClass:[NSString class]]) {
NSString *str = (NSString *)message.body;
bodyDict = [str toJSONObject];
}
NSInteger skyType = [bodyDict[@"routerType"] integerValue];
[self handleRouterType:skyType message:message];
} else if ([message.name isEqualToString:kJSOpenRoom]) {
// NSDictionary *bodyDict;
// if ([message.body isKindOfClass:[NSDictionary class]]) {
// bodyDict = message.body;
// } else if ([message.body isKindOfClass:[NSString class]]) {
// NSString *str = (NSString *)message.body;
// bodyDict = [str toJSONObject];
// }
NSString *uid = [NSString stringWithFormat:@"%@",message.body];
if (uid.length > 0) {
[XPRoomViewController openRoom:uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
}
}
}
}];
}
#pragma mark - private method
- (void)handleRouterType:(NSInteger)skyType message:(WKScriptMessage *)message {
NSDictionary *bodyDict = (NSDictionary *)message.body;
switch (skyType) {
case 1:
{
// uid
NSString *uid = [NSString stringWithFormat:@"%@", bodyDict[@"routerVal"]];
if (uid.length) {
[XPRoomViewController openRoom:uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
}
}
break;
// case P2PInteractive_SkipType_H5:
// {
// //H5
// NSString *urlString = [NSString stringWithFormat:@"%@", bodyDict[@"routerVal"]];
// if (urlString.length) {
// XCWKWebViewController *vc = [[[self class] alloc] init];
// vc.urlString = urlString;
// [self.navigationController pushViewController:vc animated:YES];
// }
// }
// break;
// case P2PInteractive_SkipType_Purse:
// {
// //
// [self h5OpenPurseAction:message];
// }
// break;
// case P2PInteractive_SkipType_Recharge:
// {
// //
// [self h5OpenChargePageAction:message];
// }
// break;
// case P2PInteractive_SkipType_Person:
// {
// // uid
// NSString *uid = [NSString stringWithFormat:@"%@", bodyDict[@"routerVal"]];
// if (uid.length) {
// [self h5OpenPersonPageAction:uid.userIDValue message:message];
// }
// }
// break;
case 7:
{
//
XPMineDressUpViewController *vc = [[XPMineDressUpViewController alloc] init];
vc.currentIndex = 1;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
break;
case 8:
{
//
XPMineDressUpViewController *vc = [[XPMineDressUpViewController alloc] init];
vc.currentIndex = 0;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
break;
// case P2PInteractive_SkipType_SystemMessage:
// {
// //
// [self h5JumpSystemMessageAction:message];
// }
// break;
case 73:
{
//
NSString *index = [NSString stringWithFormat:@"%@", bodyDict[@"routerVal"]];
XPDressUpShopViewController *vc = [[XPDressUpShopViewController alloc] init];
vc.currentIndex = [index integerValue];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
break;
case 74:
{
//
NSString *index = [NSString stringWithFormat:@"%@", bodyDict[@"routerVal"]];
XPMineDressUpViewController *vc = [[XPMineDressUpViewController alloc] init];
vc.currentIndex = [index integerValue];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
- (void)setUrl:(NSString *)urlString{
_url = urlString;
if (_url == nil) {
@@ -517,7 +636,10 @@ NSString * const kCloseWebView = @"closeWebView";
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kInitShowNav];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kCloseWebView];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJumpAppointPage];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenRoom];
}
return _userContentController;
}