간단한 전체 화면 탐색

3419 단어
안녕하세요, 오늘은 간단한 전체 화면 탐색 그림을 공유하는 데모입니다.실현하고자 하는 효과는 작은 그림을 클릭한 후에 전체 화면을 훑어보는 것이다.ViewController 2개가 필요합니다.

ViewController

#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@property(nonatomic, strong)UIImageView *imageView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
   
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 300)];
    _imageView.image = [UIImage imageNamed:@"h1.jpg"];
    _imageView.userInteractionEnabled = YES;
    [self.view addSubview:_imageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [_imageView addGestureRecognizer:tap];
}
-(void)tapAction
{
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondVC animated:NO];//        NO
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

이 작은 그림을 클릭한 후 두 번째 ViewController로 이동합니다. 여기서 점프 애니메이션을 NO로 설정하고 두 번째 ViewController가 나올 때 투명도를 0.2에서 1로 점차적으로 바꿔야 합니다. 여러분은 효과를 상상할 수 있습니다.

SecondViewController

#import "SecondViewController.h"
#define Width self.view.frame.size.width
#define Height self.view.frame.size.height
@interface SecondViewController ()
@property(nonatomic, strong)UIScrollView *scrollView;
@end

@implementation SecondViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;//           
    /* View       1*/
    self.view.alpha = .2;
    [UIView animateWithDuration:1 animations:^{
        self.view.alpha = 1;
    }];
}
-(void)viewWillDisappear:(BOOL)animated
{
    /*           */
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    _scrollView.bounces = NO;
    _scrollView.contentSize = CGSizeMake(Width * 7, Height);
    _scrollView.contentOffset = CGPointMake(0, 0);
    _scrollView.pagingEnabled = YES;
    for (NSInteger i = 1; i < 8; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(Width * (i - 1), 0, Width, Height)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"h%ld.jpg", i]];
        imageView.userInteractionEnabled = YES;
        [_scrollView addSubview:imageView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        [imageView addGestureRecognizer:tap];
        
    }
    [self.view addSubview:_scrollView];
}
-(void)tapAction
{
    //        , View       0.2    ,        
    [UIView animateWithDuration:0.6 animations:^{
        self.view.alpha = .2;
    } completion:^(BOOL finished) {
        
        [self.navigationController popToRootViewControllerAnimated:NO];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

아마 이 사고방식일 거예요. 아주 간단해요. 여러분은 계속 보완할 수 있어요.저에게 조언을 해주셔도 됩니다. 감사합니다. 오늘은 여기까지입니다.☺️

좋은 웹페이지 즐겨찾기