Я сделал код без раскадровки для Iphone 5 (8.1) с некоторыми подвидами. Это работает для устройства Iphone 5, но не для других… Я пытался вставить функцию автоматического изменения размера, но не знаю, почему она до сих пор не работает.
Вот мой код:
#import "MenuViewController.h"
#import "RevealViewController.h"
@interface MenuViewController ()
@property UIView *blurMask;
@property UIImageView *blurredBgImage;
@end
@implementation MenuViewController
@synthesize blurMask, blurredBgImage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad{
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
[super viewDidLoad];
[self Blur:blurredBgImage];
}
- (void)loadView{
[super loadView];
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view.backgroundColor = [UIColor whiteColor];
[[self view] setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[[self view] setAutoresizesSubviews:YES];
// content view
[self.view addSubview:[self createContentView]];
// slide view
[self.view addSubview:[self createScrollView]];
blurMask = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50)];
blurMask.backgroundColor = [UIColor whiteColor];
blurredBgImage.layer.mask = blurMask.layer;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
blurMask.frame = CGRectMake(blurMask.frame.origin.x,
self.view.frame.size.height - 0 - scrollView.contentOffset.y,
blurMask.frame.size.width,
blurMask.frame.size.height + scrollView.contentOffset.y);
}
- (UIView *)createContentView
{
UIView *contentView = [[UIView alloc] initWithFrame:self.view.frame];
[contentView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[contentView setAutoresizesSubviews:YES];
UIImageView *contentImage = [[UIImageView alloc] initWithFrame:contentView.frame];
contentImage.image = [UIImage imageNamed:@"back-ground.png"];
[contentView addSubview:contentImage];
return contentView;
}
- (UIView *)createScrollView{
UIView *containerView = [[UIView alloc] initWithFrame:self.view.frame];
[containerView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[containerView setAutoresizesSubviews:YES];
blurredBgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, -57, self.view.frame.size.width, 568)];
[blurredBgImage setContentMode:UIViewContentModeScaleToFill];
[containerView addSubview:blurredBgImage];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
[containerView addSubview:scrollView];
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2 - 110);
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
UIView *slideContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 455, self.view.frame.size.width, 508)];
slideContentView.backgroundColor = [UIColor clearColor];
[scrollView addSubview:slideContentView];
UILabel *slideUpLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 6, self.view.frame.size.width, 50)];
slideUpLabel.text = @"Informations";
[slideUpLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:18]];
[slideUpLabel setTextAlignment:NSTextAlignmentCenter];
[slideUpLabel setContentMode:UIViewContentModeScaleToFill];
slideUpLabel.textColor = [UIColor colorWithWhite:1 alpha:0.5];
[slideContentView addSubview:slideUpLabel];
UIImageView *slideUpImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 12, 4, 24, 22.5)];
slideUpImage.image = [UIImage imageNamed:@"up-arrow.png"];
[slideContentView addSubview:slideUpImage];
UITextView *detailsText = [[UITextView alloc] initWithFrame:CGRectMake(20, 60, 275, 350)];
detailsText.backgroundColor = [UIColor clearColor];
detailsText.text = @"Details text… with information ";
[detailsText setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]];
[detailsText setTextAlignment:NSTextAlignmentCenter];
detailsText.textColor = [UIColor colorWithWhite:1 alpha:0.6];
[slideContentView addSubview:detailsText];
UIImageView *Facebook = [[UIImageView alloc] initWithFrame:CGRectMake(105, 260, 42, 42)];
Facebook.image = [UIImage imageNamed:@"facebook.png"];
[slideContentView addSubview:Facebook];
UIImageView *Twitter = [[UIImageView alloc] initWithFrame:CGRectMake(168, 260, 42, 42)];
Twitter.image = [UIImage imageNamed:@"twitter.png"];
[slideContentView addSubview:Twitter];
UITextView *rsText = [[UITextView alloc] initWithFrame:CGRectMake(20, 300, 275, 350)];
rsText.backgroundColor = [UIColor clearColor];
rsText.text = @"Text Facebook text Twitter. mail ";
[rsText setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]];
[rsText setTextAlignment:NSTextAlignmentCenter];
rsText.textColor = [UIColor colorWithWhite:1 alpha:0.6];
[slideContentView addSubview:rsText];
UITextView *endText = [[UITextView alloc] initWithFrame:CGRectMake(25, 450, 270, 350)];
endText.backgroundColor = [UIColor clearColor];
endText.text = @"Thank you ";
[endText setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]];
[endText setTextAlignment:NSTextAlignmentCenter];
endText.textColor = [UIColor colorWithWhite:1 alpha:0.6];
[slideContentView addSubview:endText];
return containerView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)Blur:(UIView *)view {
UIView *blurView=nil;
if ([UIBlurEffect class]) {
UIBlurEffect *blurEffect= [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurView.frame = view.frame;
}else {
blurView = [[UIToolbar alloc] initWithFrame:view.bounds];
}
[blurView setTranslatesAutoresizingMaskIntoConstraints:NO];
[view addSubview:blurView];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[blurView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(blurView)]];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[blurView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(blurView)]];
}
@end
Любая идея? Обратная связь? Спасибо.