我正在使用RNBlurModalView(https://github.com/rnystrom/RNBlurModalView)来模糊我的模态视图的背景。问题是,当我滚动表格视图时,屏幕截图也不会滚动。滚动时,模糊最终会消失。我知道我需要使用表视图的内容偏移量,但我不确定如何在现有代码中实现它
RNBlurModalView.m
#pragma mark - UIView + Screenshot
@implementation UIView (Screenshot)
- (UIImage*)screenshot {
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// hack, helps w/ our colors when blurring
NSData *imageData = UIImageJPEGRepresentation(image, 1); // convert to jpeg
image = [UIImage imageWithData:imageData];
return image;
}
@end
我的实现视图的代码
- (IBAction)locationPressed:(id)sender {
UIStoryboard *storyBoard = [self storyboard];
HomeViewController *homeView = [storyBoard instantiateViewControllerWithIdentifier:@"HomeViewController"];
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self title:@"Hello world!" message:@"Pur your message here."];
[modal show];
[self presentPopupViewController:homeView animationType:MJPopupViewAnimationSlideBottomBottom];
有什么想法吗?
感谢。
答案 0 :(得分:0)
好吧,我认为问题在于,当你调用[[RNBlurModalView alloc] initWithViewController:self title:@"Hello world!" message:@"Pur your message here."];
时,该方法将自己添加到给定控制器的视图中:
- (id)initWithViewController:(UIViewController*)viewController view:(UIView*)view {
if (self = [self initWithFrame:CGRectMake(0, 0, viewController.view.width, viewController.view.height)]) {
[self addSubview:view];
...
}
所以另一个问题是当你只有一个简单的表时使用UITableViewController是可以的,但是当你想添加其他视图时它不能很好地工作,所以试试这个:
将viewDidLoad修改为如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
// create a new view to lay underneath the UITableView
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
view.autoresizingMask = self.view.autoresizingMask;
// add the uiTableView as a subview
[view addSubview:self.tableView];
self.view = view;
self.tableView.frame = view.bounds;
}
它正在创建一个UIView并将其放在UITableView下面。
下次你需要的不仅仅是普通的UITableView,而是考虑使用UIViewController,而不是UITableView作为子视图。