You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.1 KiB
64 lines
2.1 KiB
4 years ago
|
//
|
||
|
// TFPublicAdvertisementViewCell.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/23.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFPublicAdvertisementViewCell.h"
|
||
|
#import "TFWebViewController.h"
|
||
|
#import "TFAdvertisementManager.h"
|
||
|
|
||
|
@interface TFPublicAdvertisementViewCell ()
|
||
|
|
||
|
@property (nonatomic ,weak) TFAdvertisementManager *adView;
|
||
|
@property (nonatomic ,strong) TFAdvertModel *advertModel;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFPublicAdvertisementViewCell
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
[super createSubviews];
|
||
|
|
||
|
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - kMargin, kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1)) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
|
||
|
|
||
|
__weak typeof(adView) weakView = adView;
|
||
|
WS(weakSelf)
|
||
|
adView.closeBlock = ^{
|
||
|
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo(1.0);
|
||
|
}];
|
||
|
[weakSelf.mainTableView reloadData];
|
||
|
};
|
||
|
self.adView = adView;
|
||
|
[self.contentView addSubview:adView];
|
||
|
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
|
||
|
make.centerY.mas_equalTo(self.contentView.mas_centerY);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
|
||
|
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1));
|
||
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)setAdModel:(TFAdvertModel *)adModel refresh:(BOOL)refresh
|
||
|
{
|
||
|
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
|
||
|
|
||
|
_advertModel = adModel;
|
||
|
|
||
|
self.adView.advertModel = adModel;
|
||
|
if (adModel.ad_width > 0 && adModel.ad_height > 0) {
|
||
|
CGFloat scale = (CGFloat)adModel.ad_height / adModel.ad_width;
|
||
|
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo(CGRectGetWidth(self.adView.bounds) * scale);
|
||
|
}];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|