Skip to content

Instantly share code, notes, and snippets.

@shahidghafoor00
Last active September 2, 2025 10:36
Show Gist options
  • Select an option

  • Save shahidghafoor00/b582a1de47a8b47d920df1be63d063f2 to your computer and use it in GitHub Desktop.

Select an option

Save shahidghafoor00/b582a1de47a8b47d920df1be63d063f2 to your computer and use it in GitHub Desktop.
//
// DynamicTestViewController.m
// iOTG App master
//
// Created by Janak Shah on 26/01/2017.
// Copyright © 2017 Janak Shah. All rights reserved.
//
#import "DynamicTestViewController.h"
@interface DynamicTestViewController ()
@end
@implementation DynamicTestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.slideView = [[UIImageView alloc]init];
self.currentPage = 0;
[self initialiseBlanket];
}
-(BOOL) prefersStatusBarHidden {
return YES;
}
-(void)initialiseBlanket{
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
self.blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.blurView.frame = self.view.bounds;
self.blurView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.blurView];
self.backgroundView = [[UIButton alloc]initWithFrame:self.view.frame];
self.backgroundView.backgroundColor = [UIColor clearColor];
[self.backgroundView setTitle:@"Tap anywhere to begin" forState:UIControlStateNormal];
self.backgroundView.alpha = 1;
self.backgroundView.titleLabel.font = [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:24];
[self.backgroundView addTarget:self action:@selector(bigButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.backgroundView];
self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.closeButton setTitle:@"End Test" forState:UIControlStateNormal];
self.closeButton.backgroundColor = [UIColor colorWithRed:0.30 green:0.42 blue:0.53 alpha:0.7];
self.closeButton.titleLabel.font = [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:24];
self.closeButton.frame = CGRectMake(0.0, 0.0, 200.0, 200.0);
self.closeButton.alpha = 1;
[self.view addSubview:self.closeButton];
[self.closeButton addTarget:self action:@selector(closeTest) forControlEvents:UIControlEventTouchUpInside];
self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:0]];
self.currentPage = 0;
self.slideView.contentMode = UIViewContentModeScaleAspectFit;
self.slideView.frame = self.view.frame;
[self.view addSubview:self.slideView];
[self.view sendSubviewToBack:self.slideView];
}
-(void)closeTest{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self dismissViewControllerAnimated:true completion:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"closeTest" object:self];
}
-(void)bigButton{
if ([self.closeButton.currentTitle isEqualToString:@"End Test"]) {
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
self.closeButton.alpha = 0;
self.blurView.frame = CGRectMake(0, 0, self.blurView.frame.size.width, 0);
self.backgroundView.alpha = 0;
} completion:^(BOOL finished) {
self.backgroundView.backgroundColor = [UIColor clearColor];
[self.backgroundView setTitle:@"" forState:UIControlStateNormal];
self.backgroundView.alpha = 1;
self.closeButton.backgroundColor = [UIColor clearColor];
[self.closeButton setTitle:@"" forState:UIControlStateNormal];
self.closeButton.alpha = 1;
self.blurView.hidden = true;
}];
} else {
[self.backgroundView removeFromSuperview];
[self nextExternal];
}
}
-(void)nextExternal{
if (self.currentPage < self.totalPages){
self.currentPage = self.currentPage + 1;
self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:self.currentPage]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"nextExternal" object:self];
// Start the next timer based on the test type
[self startDynamic];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:@"finishExternal" object:self];
self.blurView.hidden = false;
self.closeButton.alpha = 1;
self.closeButton.frame = self.view.frame;
[self.closeButton setTitle:@"Test Complete" forState:UIControlStateNormal];
self.blurView.frame = self.view.frame;
[self performSelector:@selector(closeTest) withObject:nil afterDelay:3.0];
}
}
-(void)previousExternal{
if (self.currentPage > 0){
self.currentPage = self.currentPage - 1;
self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:self.currentPage]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"previousExternal" object:self];
}
}
-(void)startDynamic{
// Check if this is one of the new test types that use inter optotype time
if ([self.testType isEqualToString:@"Glare Country Night Driving 10%"] ||
[self.testType isEqualToString:@"Glare Country Night Driving 25%"] ||
[self.testType isEqualToString:@"Glare Country Night Driving 100%"] ||
[self.testType isEqualToString:@"Narrow Glare City Night Driving 10%"] ||
[self.testType isEqualToString:@"Narrow Glare City Night Driving 25%"] ||
[self.testType isEqualToString:@"Narrow Glare City Night Driving 100%"] ||
[self.testType isEqualToString:@"Wide Glare City Night Driving 10%"] ||
[self.testType isEqualToString:@"Wide Glare City Night Driving 25%"] ||
[self.testType isEqualToString:@"Wide Glare City Night Driving 100%"]) {
// For new test types, use interOptotypeMS for the delay
[self performSelector:@selector(nextExternal) withObject:nil afterDelay:((double)self.interOptotypeMS/1000.0)];
} else {
// For existing test types, use the original logic
if (self.currentPage % 2 == 0) {
//EVEN
[self performSelector:@selector(nextExternal) withObject:nil afterDelay:((double)self.delayMS/1000)];
} else {
//ODD
[self performSelector:@selector(nextExternal) withObject:nil afterDelay:1.0 ];
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment