I am trying to figure out how to fix this bug that only occurs on iOS 4.3. When the application launches, it displays a PDF that is scaled to fit in the UIWebView. It behaves perfectly until you pinch to zoom on the document, and then rotate it, leaving behind a black area. If you don't pinch to zoom, it doesn't leave the black area. I don't understand why this is a iOS 4.3 only issue.
Screenshot of the issue: I've been trying to solve this problem awhile now, and would greatly appreciate your help. Thank you.
Screenshots of the .xib settings:
The code I'm using is:
.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
UIWebView *webView;
}
#property (nonatomic) IBOutlet UIWebView *webView;
#end
.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webView;
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return (interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
I recall there being a few bugs with UIWebView and rotation in the past. I remember specifically that there were some rendering and resizing issues. In all honesty, if it has worked since iOS 4.3 then I think you shouldn't even bother trying to fix the issue -- in all likelihood the fix you will come up with will be hacky and irrelevant at this point.
That being said, this thread might help you solve the problem.
If it works in iOS6, it may because the shouldAutorotateToInterfaceOrientation is never be called in it. The way to handle rotation is changed in iOS6. It happened to work in your code.
Another possible solution is to use delegate of webview to wait untill it's loaded then add it to the view.
Related
I followed the iOS video processing tutorial on the OpenCV site and managed to compile and install it on the device. However when I click on the "Start" button, nothing visible happens. Apparently neither my - (void)processImage:(Mat&)image callback is never called. Could you give me some hints what could be the problem?
Some things I checked:
actionStart is called, and both log lines prints YES
the self object is valid when assigned to self.videoCamera.delegate
imageView is valid and visible on the screen
videoCamera is initialized when its start method is called
I use a iPhone 3GS for testing.
Here is the full source of my ViewController.h:
#import <UIKit/UIKit.h>
#import <opencv2/highgui/cap_ios.h>
#interface ViewController : UIViewController <CvVideoCameraDelegate>
{
IBOutlet UIImageView* imageView;
IBOutlet UIButton* button;
CvVideoCamera* videoCamera;
}
- (IBAction)actionStart:(id)sender;
#property (nonatomic, strong) CvVideoCamera* videoCamera;
#end
and ViewController.mm:
#implementation ViewController
#synthesize videoCamera;
- (void)viewDidLoad
{
[super viewDidLoad];
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscaleMode = NO;
}
#pragma mark - UI Actions
- (IBAction)actionStart:(id)sender;
{
[self.videoCamera start];
NSLog(#"video camera running: %d", [self.videoCamera running]);
NSLog(#"capture session loaded: %d", [self.videoCamera captureSessionLoaded]);
}
#pragma mark - Protocol CvVideoCameraDelegate
- (void)processImage:(cv::Mat&)image
{
// Do some OpenCV stuff with the image
cv::Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
// invert image
bitwise_not(image_copy, image_copy);
cvtColor(image_copy, image, CV_BGR2BGRA);
}
#end
I tested on an iPhone 4 and it works well. Maybe the iPhone 3GS doesn't have a front facing camera? Then you have to change this line: self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront to self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack
I'd like to create an iPhone App that allows people to listen to radio. Below is what I've done so far, but when I click on the button nothing happen, can someone please advise what I've done wrong here.
Thanks in advance.
#import <UIKit/UIKit.h>
#interface RadioViewController : UIViewController{
IBOutlet UIWebView *webView;
}
-(IBAction)radio;
#property(nonatomic,retain)UIWebView *webview;
#end
#import "RadioViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation RadioViewController
#synthesize webview;
-(IBAction)radio{
NSURL *url = [NSURL URLWithString:#"http://db5195728.tis.core.005.cdn.streamfarm.net:80/3212_erf_96_live.mp3"];
NSURLRequest *req = [NSURLRequest requestWithURL: url];
[webview loadRequest:req];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I've tried your code. It works fine here. So:
Make sure your radio is called when you tap that button. You can set a break point there or add a NSLog to see whether it is called;
Make sure your webview is correctly add to your view:shown and of the correct size.
I created a sample in which i imported a word(.docx)on to the uiwebview and displayed.I got the output but i don't want to display the horizontal scroll bar and the vertical scroll also working not properly i can see the black space behind the webview when i scroll it vertically.
Here is my code:
#import <UIKit/UIKit.h>
#interface userguideLinesNewViewController : UIViewController {
IBOutlet UIWebView *webView;
}
#property (nonatomic,retain) UIWebView *webView;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews;
#end
#import "userguideLinesNewViewController.h"
#implementation userguideLinesNewViewController
#synthesize webView;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"BTBP CLARITY SKIN ADVISORuser.docx" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViews loadRequest:request];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadDocument:#"BTBP CLARITY SKIN ADVISORuser.docx" inView:self.webView];
}
You could check others topics about this : Stop UIWebView from "bouncing" vertically? :-)
There isn't a method like in UIScrollView. But there is some kind of way to achieve your goal ;-)
Here is my way.
- (void)disableBounce {
for (id subview in self.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
}
Enjoy...
I'm trying to implement a UIWebViewDelegate in my application and I cannot for the life of me get it to work. I would really appreciate a second set of eyes on this.
I know the name MapViewController is confusing, but the WebView is controlling a map (not UIMapView).
Here's the bulk of the code:
MapViewController.h
#import <UIKit/UIKit.h>
#import <UIKit/UIWebView.h>
#interface MapViewController : UIViewController<UIWebViewDelegate> {
IBOutlet UIWebView *webView;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#end
MapViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
webView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"map" ofType:#"html"]isDirectory:NO]];
[webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(#"Done loading.");
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return NO;
}
- (void)dealloc {
webView.delegate = nil;
[webView release]
[super dealloc];
}
Thanks for any help!
Does the initial page you're loading actually display? Are you sure you connected your webview in Interface Builder?
go interface builder , connect the delegate to the file's owner , then it should work.
Open Interface Builder
Right click on the Web View object
Drag the delegate onto files owner.
Things to check:
if map.html is in the bundle. Put it on the root of the bundle, not on resources.
if it is, right click on it, and choose get info. Verify on TARGETS if the target is checked for the file.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return YES; // for all supported oreintation.
}
As well as my question "Removing MKMapView Annotations causes leaks." I have discovered that if you create a view based project, add a UISearchBar and MKMapView into the view's NIB, wire up the delegates (I'm not creating any methods as we don't actually need to do anything to trigger the leaks), link in the MapKit and fire up the project, then simply clicking in the UISearchBar causes a 1k+ leak. This doesn't happen unless you have both UISearchBar and MKMapView in a view. I have the same issues when creating the views from code. I thought a NIB might behave differently, but it doesn't.
Is MKMapView leaky, or am I doing something wrong.
To replicate the issue with code try the code below - I created a new "view based application" project
TestMapViewFromCodeViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface TestMapViewFromCodeViewController : UIViewController {
UISearchBar *searchBar;
MKMapView *mapView;
}
#property (nonatomic, retain) MKMapView *mapView;
#property (nonatomic, retain) UISearchBar *searchBar;
#end
TestMapViewFromCodeViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UISearchBar * tmpSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,40.0)];
[self.view addSubview:tmpSearchBar];
[self setSearchBar:tmpSearchBar];
[tmpSearchBar release];
MKMapView *tmpMapView=[[MKMapView alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)];
tmpMapView.showsUserLocation=FALSE;
[self.view insertSubview:tmpMapView atIndex:0];
[self setMapView:tmpMapView];
[tmpMapView release];
}
- (void)dealloc {
[mapView release];
[searchBar release];
[super dealloc];
}
Although I've retained the subviews with mapView and searchBar, this is probably unnecessary to replicate the issue.
In testing this code prior to publishing here I've just noticed that this leak does not occur in the simulator - only on my phone...
Yes.
There is a known leaks on 3.0's MKMapViews. The leak occurs when you deallocate the MKMapView This is fixed in later releases. The workaround is to have a single MKMapView and reuse it.
https://devforums.apple.com/message/129740#129740
For what its worth, there are similar related questions here:
https://stackoverflow.com/questions/5935243/mkmapview-rame-et-fuite-memoire-apple
Can the memory used by MKMapView be released some how?
MKMapView Memory Leak in iPhone Application