Sus*_*nta 2 mobile-safari uiwebview ios7
如果您在ios 7中看到safari应用程序左右拖动以查看网页的历史记录.它还会在拖动时显示上一页的内容.我想要使用UIWebiview的类似功能.
我可以前进和后退页面但是如何实现显示以前内容的拖动功能?
注意:这只是iOS 7.对于iOS 6,您应该使用PanGestureRecognizer并检测它是左还是右.
你需要两个属性:
@property (nonatomic, strong) UIImageView * imgvcChild1;
@property (retain, strong) IBOutlet UIWebView *webView;
Run Code Online (Sandbox Code Playgroud)
首先,将手势识别器添加到webView:
[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(EdgeLeftPanDetected:)];
panLeft.edges = UIRectEdgeLeft;
[self.webView addGestureRecognizer:panLeft];
Run Code Online (Sandbox Code Playgroud)
控制手势:
- (void) EdgeLeftPanDetected:(UIScreenEdgePanGestureRecognizer*)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
UIGraphicsBeginImageContext ( self.webView.frame.size );
[self.webView.layer renderInContext:UIGraphicsGetCurrentContext() ];
UIImage *grab = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if ( _imgvcChild1 ) [ _imgvcChild1 removeFromSuperview ];
_imgvcChild1 = [[ UIImageView alloc ] initWithImage:grab ];
_imgvcChild1.frame = self.webView.frame;
_imgvcChild1.userInteractionEnabled = YES;
_imgvcChild2 = [self.arrayImagenes lastObject];
if ([self.webView canGoBack]) {
[self.webView goBack];
}
[ self.view addSubview:_imgvcChild1 ];
}
if (gesture.state == UIGestureRecognizerStateChanged) {
_imgvcChild1.frame = CGRectMake([ gesture locationInView:_imgvcChild1.superview ].x, _imgvcChild1.frame.origin.y, _imgvcChild1.frame.size.width, _imgvcChild1.frame.size.height);
}
}
if (gesture.state == UIGestureRecognizerStateEnded) {
[_imgvcChild1 removeFromSuperview];
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个原型,它需要大量的工作,它只是为了回头而你回去的页面没有动画.如果你想在上一页中有动画,你需要在加载新页面之前创建一个图像并将其存储在一个图像上NSMutableArray,然后用不同的动画显示它(这个图像像屏幕的-1/4一样开始,就像速度的1/4 imgvcChild1)
UIImageViews如果你想要前进,你还需要另一个右手势识别器和另一个阵列.
| 归档时间: |
|
| 查看次数: |
3026 次 |
| 最近记录: |