VisionWallPaperOffline-8-19/HDwallpaper/LuxADManager/LuxADSSModeVC.m
2024-07-29 18:57:41 +08:00

123 lines
4.6 KiB
Objective-C

//
// LuxADSSModeVC.m
// TallPaper
//
// Created by aaa on 2024/7/26.
//
#import "LuxADSSModeVC.h"
#import "LuxNetManager.h"
#import "LuxADManager.h"
@interface LuxADSSButton : UIButton
@property (nonatomic,weak) LuxADManagerInterstitialItem *item;
@end
@implementation LuxADSSButton
@end
@interface LuxADSSModeVC ()
@property (nonatomic,strong) UITextView *adInfoTextView;
@property (nonatomic,strong) UITextView *actionTextView;
@end
@implementation LuxADSSModeVC
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
[super viewDidLoad];
__block CGFloat currY = 80.0;
CGFloat cellHeight = 50;
CGFloat cellPadding = 20;
CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
CGFloat cellWidth = (screenW - cellPadding*2);
[[[LuxADManager shareInstance] allInterstitialAds] enumerateObjectsUsingBlock:^(LuxADManagerInterstitialItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
CGRect rect = CGRectMake(cellPadding, currY, cellWidth, cellHeight);
LuxADSSButton *button = [LuxADSSButton new];
button.item = obj;
button.frame = rect;
button.tag = idx + 1;
obj.tapPointX = @(button.center.x);
obj.tapPointY = @(button.center.y);
[button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[NSString stringWithFormat:@"ID: %@",obj.adItem.adUnitIdentifier] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:18];
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
currY += cellPadding + cellHeight;
}];
_adInfoTextView = [UITextView new];
_adInfoTextView.frame = CGRectMake(0, currY, screenW*0.5, screenH - currY - 10);
[self.view addSubview:_adInfoTextView];
_adInfoTextView.backgroundColor = [UIColor purpleColor];
_adInfoTextView.editable = NO;
_adInfoTextView.textColor = [UIColor whiteColor];
_adInfoTextView.font = [UIFont systemFontOfSize:14];
_adInfoTextView.layoutManager.allowsNonContiguousLayout = NO;
_actionTextView = [UITextView new];
_actionTextView.frame = CGRectMake(_adInfoTextView.frame.size.width, _adInfoTextView.frame.origin.y, _adInfoTextView.frame.size.width, _adInfoTextView.frame.size.height);
[self.view addSubview:_actionTextView];
_actionTextView.backgroundColor = [UIColor lightGrayColor];
_actionTextView.editable = NO;
_actionTextView.textColor = [UIColor whiteColor];
_actionTextView.font = [UIFont systemFontOfSize:14];
_actionTextView.layoutManager.allowsNonContiguousLayout = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adInfoNtification:) name:kLuxADSSModeVC_Notification_AdInfo object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionInfoNtification:) name:kLuxADSSModeVC_Notification_ActionInfo object:nil];
}
- (void)clickAction:(LuxADSSButton *)sender {
sender.item.actionBlock(self);
NSLog(@"rect:%@",NSStringFromCGRect(sender.frame));
}
- (void)actionInfoNtification:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *info = notification.userInfo[@"info"];
NSString *text = _actionTextView.text ? _actionTextView.text : @"";
text = [text stringByAppendingFormat:@"\n\n%@",info];
_actionTextView.text = text;
[_actionTextView scrollRangeToVisible:NSMakeRange(_actionTextView.text.length, 1)];
});
}
- (void)adInfoNtification:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *info = notification.userInfo[@"info"];
NSString *text = _adInfoTextView.text ? _adInfoTextView.text : @"";
text = [text stringByAppendingFormat:@"\n\n%@",info];
_adInfoTextView.text = text;
[_adInfoTextView scrollRangeToVisible:NSMakeRange(_actionTextView.text.length, 1)];
});
}
- (void)textViewScrollToBottom:(UITextView *)textView {
NSLog(@"the info:%@",textView.text);
CGFloat bottomOffset = textView.contentSize.height - textView.bounds.size.height;
NSLog(@"the %@, bound:\n%@",NSStringFromCGSize(textView.contentSize),NSStringFromCGSize(textView.bounds.size));
if (bottomOffset > 0) {
[textView setContentOffset:CGPointMake(0, bottomOffset)];
}
}
@end