当呈现视图并且点击UITextFIEld时,应用程序变得无响应(未冻结,只是没有响应触摸).几乎就像键盘出现但没有出现.委托方法被正确调用.如果我删除self.vIEw.supervIEw.bounds = CGRectMake(0,300,250);从vIEwWillLayoutSubvIEws方法键盘工作,但视图现在是一个完整大小的UIModalPresentationFormSheet样式.
这只发生在iOS 8中,所以我只能假设键盘显示的方式以及我屏蔽/调整视图的方式存在问题,但我对解决方案感到茫然.
呈现VIEwController –
UserLoginVIEwController *loginVC = [[UserLoginVIEwController alloc] initWithNibname:@"UserLoginVIEwController" bundle:nil];loginVC.modalPresentationStyle = UIModalPresentationFormSheet;loginVC.delegate = self;[self presentVIEwController:loginVC animated:YES completion:nil];
编辑视图边界 –
- (voID)vIEwWillLayoutSubvIEws { [super vIEwWillLayoutSubvIEws]; self.vIEw.supervIEw.layer.cornerRadius = 10.0; self.vIEw.supervIEw.layer.masksToBounds = YES; self.vIEw.supervIEw.bounds = CGRectMake(0,250);}解决方法 在iOS8中,您不应更改vIEwWillLayoutSubvIEws中的超视图边界,因为它会导致无限循环.
编辑:
在iOS8属性preferredContentSize运行良好.
您应该以这种方式更改代码:
UserLoginVIEwController *loginVC = [[UserLoginVIEwController alloc] initWithNibname:@"UserLoginVIEwController" bundle:nil]; loginVC.modalPresentationStyle = UIModalPresentationFormSheet; loginVC.delegate = self; if(IS_IOS8) { loginVC.preferredContentSize = CGSizeMake(300,250); } [self presentVIEwController:loginVC animated:YES completion:nil];
编辑视图边界 –
- (voID)vIEwWillLayoutSubvIEws{ [super vIEwWillLayoutSubvIEws]; self.vIEw.supervIEw.layer.cornerRadius = 10.0; self.vIEw.supervIEw.layer.masksToBounds = YES; if(!IS_IOS8) { self.vIEw.supervIEw.bounds = CGRectMake(0,250); }}
另一种为您提供更多自定义选项的方法是使用UIPresentationController和UIVIEwControllerTransitioningDelegate.看看下面的代码.
父视图控制器:
_aboutVIEwController = [[AboutVIEwController alloc] init]; _aboutVIEwController.modalPresentationStyle = UIModalPresentationFormSheet; if(IS_IOS8) { if(aboutTransitioningDelegate == nil) { aboutTransitioningDelegate = [[AboutTransitioningDelegate alloc] init]; } _aboutVIEwController.TransitioningDelegate = aboutTransitioningDelegate; _aboutVIEwController.modalPresentationStyle = UIModalPresentationCustom; } [self presentVIEwController:_aboutVIEwController animated:YES completion:nil];
AboutVIEwController.m
#import "AboutVIEwController.h"@interface AboutVIEwController ()@end@implementation AboutVIEwController- (voID)vIEwWillLayoutSubvIEws{ [super vIEwWillLayoutSubvIEws]; if(IS_IOS8) { return; } CGSize displaySize = CGSizeMake(320,462); self.vIEw.supervIEw.bounds = CGRectMake(0,displaySize.wIDth,displaySize.height);}@end
AboutTransitioningDelegate.h:
@interface AboutTransitioningDelegate : NSObject <UIVIEwControllerTransitioningDelegate>@end
AboutTransitioningDelegate.m:
#import "AboutTransitioningDelegate.h"#import "AboutPresentationController.h"@implementation AboutTransitioningDelegate-(UIPresentationController *)presentationControllerForPresentedVIEwController:(UIVIEwController *)presented presentingVIEwController:(UIVIEwController *)presenting sourceVIEwController:(UIVIEwController *)source{ return [[AboutPresentationController alloc] initWithPresentedVIEwController:presented presentingVIEwController:presenting];}@end
AboutPresentationController.h
#import <UIKit/UIKit.h>@interface AboutPresentationController : UIPresentationController@end
AboutPresentationController.m
#import "AboutPresentationController.h"@implementation AboutPresentationController-(CGRect)frameOfPresentedVIEwInContainerVIEw{ CGSize displaySize = CGSizeMake(320,462); if([[Config sharedInstance] latestVersionFromAppstoreInstalled]) { displaySize = CGSizeMake(320,416); } CGRect r = CGRectZero; r.size = displaySize; r.origin.y = self.containerVIEw.bounds.size.height/2 - displaySize.height/2; r.origin.x = self.containerVIEw.bounds.size.wIDth/2 - displaySize.wIDth/2; return r;}-(voID)containerVIEwWillLayoutSubvIEws{ [super containerVIEwWillLayoutSubvIEws]; self.presentedVIEw.frame = [self frameOfPresentedVIEwInContainerVIEw];}@end
项目名 – Prefix.pch
#define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8)总结
以上是内存溢出为你收集整理的在iOS 8中呈现隐藏键盘时编辑UIView的边界全部内容,希望文章能够帮你解决在iOS 8中呈现隐藏键盘时编辑UIView的边界所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)