203 lines
6.7 KiB
Objective-C
Executable File

//
// FirstViewController.m
// Talk
//
// Created by xuzs on 22/10/11.
// Copyright (c) 2022年 xuzs. All rights reserved.
//
#import "FaceUpload.h"
#import "UI.h"
#import "HttpManager.h"
#import "Msg.h"
#import "Pub.h"
#import "sysInfo.h"
#import "HttpManager.h"
#import "FaceSubPage.h"
@interface FaceUpload ()
@property (nonatomic, strong)UIView *rview;
//翻页视图控制器对象
@property (nonatomic, strong) UIPageViewController * pageViewControl;
@property (nonatomic, strong) NSMutableArray* dataArray;
@end
@implementation FaceUpload
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setNavTitle:@"人脸开门"];
[self setupViews];
[self setUI];
[self setData];
}
- (void)setupViews{
[self.view addSubview:self.rview];
}
- (void)ReLoad:(int)index{
NSArray *viewControlles = self.navigationController.viewControllers;
NSMutableArray *newviewControlles = [NSMutableArray array];
if ([viewControlles count] > 0) {
for (int i=0; i < [viewControlles count]-1; i++) {
[newviewControlles addObject:[viewControlles objectAtIndex:i]];
}
}
FaceUpload *face = [[FaceUpload alloc] init];
face.index0 = index;
face.equid = _equid;
[self.navigationController pushViewController:face animated:YES];
[newviewControlles addObject:face];
[self.navigationController setViewControllers:newviewControlles animated:YES];
}
- (void)setData{
[HttpManager getPhotos:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:self.equid HttpResultHandler:^(NSDictionary *json) {
_dataArray = [[NSMutableArray alloc]init];
if([[json objectForKey:@"result"] isEqualToString:@"ok"]){
//{"no":5,"username":"13430525341","stime":"2022-11-08 09:58","photo":""}
NSArray *arr = [json objectForKey:@"data"];
for(int i=0;i<arr.count;i++){
FaceSubPage * item = [[FaceSubPage alloc] init];
item.parent = self;
item.no = [[NSString alloc] initWithFormat:@"%@",[arr[i] valueForKey:@"no"]] ;
item.hit.text = [[NSString alloc] initWithFormat:@"%@上传于%@",[arr[i] valueForKey:@"username"],[arr[i] valueForKey:@"stime"]];
//[_dataArray insertObject:item atIndex:_dataArray.count-1];
NSData * imageData =[[NSData alloc] initWithBase64EncodedString:[arr[i] valueForKey:@"photo"] options:NSDataBase64DecodingIgnoreUnknownCharacters];
[item.imgView setImage:[[UIImage alloc] initWithData:imageData]];
item.imgView.layer.opacity = 1;
[_dataArray addObject:item];
}
}
if(_dataArray.count<5){
FaceSubPage * item = [[FaceSubPage alloc] init];
item.parent = self;
item.hit.text = @"请上传正面清晰大头照";
item.button.backgroundColor = [UI colorWithHex:0x378fe8];
[item.button setTitle:@"拍照上传人脸" forState:UIControlStateNormal];
[_dataArray addObject:item];
}
int index2 = 0;
if(_index0==-2){
index2 = _dataArray.count - 2;
if(index2<0)index2 = 0;
}
_pageViewControl = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionSpineLocationKey:@0,UIPageViewControllerOptionInterPageSpacingKey:@10}];
self.view.backgroundColor = [UIColor greenColor];
//设置翻页视图的尺寸
_pageViewControl.view.bounds = self.rview.bounds;
//设置数据源与代理
_pageViewControl.dataSource = self;
_pageViewControl.delegate = self;
//设置初始界面
[_pageViewControl setViewControllers:@[_dataArray[index2]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
//设置是否双面展示
_pageViewControl.doubleSided = NO;
//创建初始界面
[self.rview addSubview:_pageViewControl.view];
}];
}
- (void)setUI{
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
}
//翻页控制器进行向前翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
int index = (int)[_dataArray indexOfObject:viewController];
if (index==0) {
return nil;
}else{
return _dataArray[index-1];
}
}
//翻页控制器进行向后翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
int index = (int)[_dataArray indexOfObject:viewController];
if(index+1 >= _dataArray.count){
return nil;
}
else{
return _dataArray[index+1];
}
// if (index==9) {
// return nil;
// }else{
// if (_dataArray.count-1>=(index+1)) {
// return _dataArray[index+1];
// }else{
// FaceSubPage * item = [[FaceSubPage alloc] init];
// item.hit.text = [[NSString alloc] initWithFormat:@"%d"]
// [_dataArray addObject:item];
// return item;
// }
// }
}
//屏幕旋转触发的代理方法
- (UIPageViewControllerSpineLocation) pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
return UIPageViewControllerSpineLocationMin;
}
//设置分页控制器的分页数
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
return _dataArray.count;
}
//设置初始的分页点
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{
int index2 = 0;
if(_index0==-2){
index2 = _dataArray.count - 2;
if(index2<0)index2 = 0;
}
return index2;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark Property Accessors
- (UIView *)rview
{
if (!_rview) {
_rview = [[UIView alloc] init];
_rview.backgroundColor = [UIColor colorWithRed:189/255. green:211/255. blue:194/255. alpha:1];
}
return _rview;
}
@end