1.隱藏上下滾動時出邊界的后面的黑色的陰影 - (void) hideGradientBackground:(UIView*)theView { for (UIView * subview in theView.subviews) { if ([subview isKindOfClass:[UIImageView class]]) subview.hidden = YES; [self hideGradientBackground:subview]; } } 2. 禁用拖拽時的反彈效果 [(UIScrollView *)[[webView subviews] objectAtIndex:0] setBounces:NO]; 3. 判斷用戶點擊類型 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { switch (navigationType) { //點擊連接 case UIWebViewNavigationTypeLinkClicked: { NSLog(@"clicked"); } break; //提交表單 case UIWebViewNavigationTypeFormSubmitted: { NSLog(@"submitted"); } default: break; } return YES; }
#import "BaseViewController.h" @interface BaseViewController () { UIWebView *webview; } @end @implementation BaseViewController #pragma mark -life cicry - (void)viewDidLoad { [super viewDidLoad]; webview=[[UIWebView alloc] initWithFrame:self.view.bounds]; webview.delegate=self;//因為這個代理設置的self [self.view addSubview:webview]; [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.requestUrl]]]; [webview release]; UIScrollView *scollview=(UIScrollView *)[[webview subviews]objectAtIndex:0]; scollview.bounces=NO; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)viewDidUnload{ [super viewDidUnload]; self.requestUrl=nil; } - (void)dealloc { [_requestUrl release]; [super dealloc]; }