I'm adding a GIF image in UIWbeview in Objective-C. The problem is that the image size doesn't fit in the screen and the contents above the gif video is not showing. How can I adjust the image size and show the buttons above it.
My code is:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"back" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:#"gif" textEncodingName:NULL baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
// Do any additional setup after loading the view.
}
You can move your code to viewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"back" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:#"image/gif" textEncodingName:#"UTF-8" baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
}
Related
I want to use AsyncImageView to load and image from a URL and then add this image to a UIView. I have retrieved my URL but when I try to use the method loadImageWithURL I can't because it is not declared in the interface for AsyncImageView but rather for AsyncImageLoader. Should I be using the interface AsyncImageLoader instead? Can anybody help me figure out how to modify my code to do this?
Link to image with code:
http://imgur.com/QPv32td
- (void)viewDidLoad {
CGRect frame = image.frame;
AsyncImageView* asyncImage = [[AsyncImageView alloc] initWithFrame:frame];
asyncImage.tag = 999;
AppDelegate *thisDelegate = [[UIApplication sharedApplication] delegate];
if (thisDelegate.isEchoesUser == YES) {
url = [NSURL URLWithString:[[NSString stringWithFormat:#"%#%#", ECHOES_REST_SERVICE_THUMB3,
[imageURL stringByReplacingOccurrencesOfString:ECHOES_REST_ADDRESS withString:#""]]
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
}else if (thisDelegate.isEchoesUser == NO){
url = [NSURL URLWithString:[[NSString stringWithFormat:#"%#%#", REST_SERVICE_THUMB3,
[imageURL stringByReplacingOccurrencesOfString:REST_ADDRESS withString:#""]]
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
}
[asyncImage loadImageWithURL:url];
[image addSubview:asyncImage];
// Set the caption;
[caption setText:captionText];
[super viewDidLoad];
}
Use a AsyncImageLoader instead, AsyncImageView doesn't have this function
I have a Gif in a UIWebView, but when the animation ends, it stops.
How I can do to never stop?
This is my code:
self.video is my UiWebView
my gif is videoGif.gif
- (void)viewDidLoad
{
[super viewDidLoad];
self.video.delegate=self;
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"videoGif" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
[self.video loadData:gif MIMEType:#"image/gif" textEncodingName:nil baseURL:nil];
self.video.userInteractionEnabled = NO;
self.video.scalesPageToFit=YES;
self.video.contentMode = UIViewContentModeScaleAspectFit;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
self.video.scalesPageToFit=YES;
self.video.contentMode = UIViewContentModeScaleAspectFit;
}
Thanks!!
You can you use UIView Animations. Here i use UIButton for animation. It may be and alternative way. Here my code:
NSMutableArray *imageArray=[NSMutableArray new];
for(int i=1;i<=16;i++){
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:#"win_%d.png",i]]];
}
[animatedButton setImage:[UIImage imageNamed:#"win_1.png"] forState:UIControlStateNormal];
[animatedButton.imageView setAnimationImages:[imageArray copy]];
animatedButton.imageView.animationDuration = .50;
[animatedButton.imageView startAnimating];
Ok so im pretty new to Xcode and am trying to make a simple app. i need my sound to keep looping and stop when i press the stop button. Please help and thanks in advance. here is my code so far.
as you can see the sound plays once then stops .
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize Images;
-(IBAction)start:(id)sender;{
AudioServicesPlaySystemSound(PlaySoundID);
Images.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Light.png"],
[UIImage imageNamed:#"Light1.png"],
[UIImage imageNamed:#"Light2.png"],
[UIImage imageNamed:#"Light3.png"], nil];
Images.animationRepeatCount = 99999999;
Images.animationDuration = .2;
[Images startAnimating];
[self.view addSubview:Images];
}
-(IBAction)stop:(id)sender;{
[Images stopAnimating];
}
- (void)viewDidLoad
{
NSURL *SoundURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"Siren" ofType:#"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL, &PlaySoundID);
[super viewDidLoad];
Images.image = [UIImage imageNamed:#"Light.png"];
[self.view addSubview:Images];
[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
NSURL *soundURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"Siren"
ofType:#"wav"]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL
error:nil];
for "infinite" number of loops:
audioPlayer.numberOfLoops = -1;
Using the latest code of GPUImage from GitHub I tried the following:
#import "ViewController.h"
#import "GPUImage.h"
#import <AssetsLibrary/AssetsLibrary.h>
#interface ViewController ()
{
GPUImageOutput<GPUImageInput> *filter0;
GPUImageMovieWriter *movieWriter;
GPUImageMovie *movie1, *movie2;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"started");
NSURL *url = [[NSBundle mainBundle] URLForResource:#"video1" withExtension:#"MOV"];
movie1 = [[GPUImageMovie alloc] initWithURL:url];
movie1.playAtActualSpeed = YES;
NSURL *url2 = [[NSBundle mainBundle] URLForResource:#"video2" withExtension:#"MOV"];
movie2 = [[GPUImageMovie alloc] initWithURL:url2];
movie2.playAtActualSpeed = YES;
filter0 = [[GPUImageNormalBlendFilter alloc] init];
[filter0 forceProcessingAtSize:CGSizeMake(1080, 1920)];
[movie1 addTarget:filter0];
[movie2 addTarget:filter0]; // movie2 adding Filter
GPUImageView *filterView= (GPUImageView *) self.view;
filterView.fillMode = kGPUImageFillModePreserveAspectRatio;
[filter0 addTarget:filterView];
[movie1 startProcessing];
[movie2 startProcessing]; // movie2 startprocessing
}
#end
Basically, I want to blend two videos and display it on the screen, but after running, nothing gets displayed, only black screen is being shown and the first frame of the 2nd video is shown after few seconds.
** I have added the "Header Search Path" and also given the flag -ObjC in "Other Linkers"
Now if I add a PixellateFilter to any one of the video(say movie1, commenting movie2 adding Filter and movie2 startprocessing then the result is coming.
So my question is why the blend is not happening for two videos, am I doing something wrong.
Thanks in advance
NSURL *url = [[NSBundle mainBundle] URLForResource:#"abc" withExtension:#"mp4"];
gpuIM = [[GPUImageMovie alloc] initWithURL:url];
gpuIM.playAtActualSpeed = YES;
NSURL *url2 = [[NSBundle mainBundle] URLForResource:#"def" withExtension:#"mov"];
movie2 = [[GPUImageMovie alloc] initWithURL:url2];
movie2.playAtActualSpeed = YES;
filter0 = [[GPUImageColorDodgeBlendFilter alloc] init];
[gpuIM addTarget:filter0];
[movie2 addTarget:filter0];
[filter0 addTarget:_view0];
[gpuIM startProcessing];
[movie2 startProcessing];
Another approach would be create a avasset from URL , use it in GPUImageMovie,most importantly make the GPUImageMovie instance global.
My code is working fine for iOS 7 but crashes in iOS 6. My app is working fine but the problem occurs when i click on a tab else its working fine.
Checked the link :EXC_BAD_ACCESS While switching tabControllers but no luck.
Below is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.webView = [[UIWebView alloc] init];
self.view.backgroundColor = [UIColor colorWithPatternImage:[JLTBackgroundHelper getBackgroundImageForView]];
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
UIViewController *rootVC = [[UIViewController alloc] init];
rootVC.title = #"Contact JLT Sport";
rootVC.view = self.webView;
self.viewControllers = #[rootVC];
NSString *fileName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad-specific
fileName = #"contact_ipad";
} else {
// iPhone-specific
fileName = #"contact";
}
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:#"html" inDirectory:#"Assets/web"];
NSURL *url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
_webView.delegate= self;
}
//send external URL requests to Safari
- (BOOL) webView:(UIWebView*)wv shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navType
{
if (navType == UIWebViewNavigationTypeLinkClicked
&& [request.URL.scheme hasPrefix:#"http"])
{
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
#end
Plese guide/suggest.
try this :
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.webView = [[UIWebView alloc] init];
self.view.backgroundColor = [UIColor colorWithPatternImage:[JLTBackgroundHelper getBackgroundImageForView]];
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
UIViewController *rootVC = [[UIViewController alloc] init];
rootVC.title = #"Contact JLT Sport";
rootVC.view = self.webView;
self.viewControllers = #[rootVC];
NSString *fileName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad-specific
fileName = #"contact_ipad";
} else {
// iPhone-specific
fileName = #"contact";
}
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:#"html" inDirectory:#"Assets/web"];
NSURL *url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
self.webView.delegate= self;
}
if above solution does not work then try this:
Debug with Instrument
Go to Product >> Profile >> All > Zoombies
Press "Record" button on top left corner
Perform your task and when application get EXC_BAD_ACCESS the instrument give that line where the application was being crash.
Also debug in this method to:[JLTBackgroundHelper getBackgroundImageForView];
**Make sure that all variable is being get memory before use it.**
May be the resin is that some method is depreciated in iOS 7.
These are the possible scenario of application is being crash and its solution.