I want to load images like gif. It work perfectly when i go to viewcontroller by push segue but when i go to viewcontroller by modal segue not load images in imageview.
_ivDummy.animationImages = [NSMutableArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"7.png"],
[UIImage imageNamed:#"8.png"],
nil];
[_ivDummy setBackgroundColor:[UIColor redColor]];
_ivDummy.animationDuration = 1.0f;
_ivDummy.animationRepeatCount = INFINITY;
[_ivDummy startAnimating];
Please, Help me.
In Progress Hud
[indicator removeFromSuperview];
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];
animatedImageView.animationImages = [NSMutableArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"7.png"],
[UIImage imageNamed:#"8.png"],
nil];
//[animatedImageView setBackgroundColor:[UIColor redColor]];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = INFINITY;
[animatedImageView startAnimating];
indicator=animatedImageView;
[self addSubview:indicator];
Instead of using
- (void)viewDidLoad method try using
- (void)viewWillAppear:(BOOL)animated
-(void)viewWillAppear:(BOOL)animated
{
_ivDummy.animationImages = [NSMutableArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"7.png"],
[UIImage imageNamed:#"8.png"],
nil];
[_ivDummy setBackgroundColor:[UIColor redColor]];
_ivDummy.animationDuration = 1.0f;
_ivDummy.animationRepeatCount = INFINITY;
[_ivDummy startAnimating];
}
You can override this method to perform custom tasks associated with displaying the view.
Related
The thing is i can add segments as much as i want if i use text but if i use image means i can not able to add more than 6 segments on iphone.
help me out.
UIImage* resetImage = [UIImage imageNamed:#"Reset_V1"];
UIImage* wlwwImage = [UIImage imageNamed:#"Reset_V1"];
UIImage* huImage = [UIImage imageNamed:#"HU_PI_V1"];
UIImage* panImage = [UIImage imageNamed:#"Panning_V1"];
UIImage* disImage = [UIImage imageNamed:#"Distance_V1"];
UIImage* areaImage = [UIImage imageNamed:#"Reset_V1"];
UIImage* clrImage = [UIImage imageNamed:#"Clear_V1"];
UIImage* presetImage = [UIImage imageNamed:#"Presets_V1"];
mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage, nil];
segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[segmentControl addTarget:self action:#selector(whichSegment:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentControl];
I try with same code and it work
Output:
Code:
UIImage* resetImage = [UIImage imageNamed:#"Image"];
UIImage* wlwwImage = [UIImage imageNamed:#"Image"];
UIImage* huImage = [UIImage imageNamed:#"Image"];
UIImage* panImage = [UIImage imageNamed:#"Image"];
UIImage* disImage = [UIImage imageNamed:#"Image"];
UIImage* areaImage = [UIImage imageNamed:#"Image"];
UIImage* clrImage = [UIImage imageNamed:#"Image"];
UIImage* presetImage = [UIImage imageNamed:#"Image"];
UIImage* presetImage1 = [UIImage imageNamed:#"Image"];
UIImage* presetImage2= [UIImage imageNamed:#"Image"];
UIImage* presetImage3= [UIImage imageNamed:#"Image"];
NSArray *mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage,presetImage1,presetImage2,presetImage3, nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[self.view addSubview:segmentControl];
Download demo project
Link
If your image path is not valid then it will show only segment with correct image
Code(with bug)
// Do any additional setup after loading the view, typically from a nib.
UIImage* resetImage = [UIImage imageNamed:#"Image"];
UIImage* wlwwImage = [UIImage imageNamed:#"Image"];
UIImage* huImage = [UIImage imageNamed:#"Image"];
UIImage* panImage = [UIImage imageNamed:#"Image"];
UIImage* disImage = [UIImage imageNamed:#"Image"];
UIImage* areaImage = [UIImage imageNamed:#"Image1"]; // wrong image name
UIImage* clrImage = [UIImage imageNamed:#"Image1"]; // wrong image name
UIImage* presetImage = [UIImage imageNamed:#"Image1"]; // wrong image name
UIImage* presetImage1 = [UIImage imageNamed:#"Image1"]; // wrong image name
UIImage* presetImage2= [UIImage imageNamed:#"Image1"]; // wrong image name
UIImage* presetImage3= [UIImage imageNamed:#"Image1"]; // wrong image name
NSArray *mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage,presetImage1,presetImage2,presetImage3, nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[self.view addSubview:segmentControl];
So I have got this method in my code that shows a really nice loader in my app. The best way I was told to do this, is with the UIImageView.
I set up all the parameters, and I think I have covered everything I needed to. The loader continues to 'spin' in the background of my app, and corresponding UI elements adjust their alpha, based on when I need to show the loader, in the case the UITableView.
However, when testing on iOS 7 and profiling energy diagnostics and time profiling, I found that it takes a whole lot out of the app. Is there any way to make this more efficient?
- (void)displayLoadingCircle:(BOOL)display {
UIView *placeholderView = [[UIView alloc] initWithFrame:self.view.bounds];
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(94, 240, 125, 125)];
[animatedImageView setContentMode:UIViewContentModeScaleToFill];
[animatedImageView setAlpha:0.7f];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"loader-1 (dragged).png"],
[UIImage imageNamed:#"loader-2 (dragged).png"],
[UIImage imageNamed:#"loader-3 (dragged).png"],
[UIImage imageNamed:#"loader-4 (dragged).png"],
[UIImage imageNamed:#"loader-5 (dragged).png"],
[UIImage imageNamed:#"loader-6 (dragged).png"],
[UIImage imageNamed:#"loader-7 (dragged).png"],
[UIImage imageNamed:#"loader-8 (dragged).png"],
[UIImage imageNamed:#"loader-9 (dragged).png"],
[UIImage imageNamed:#"loader-10 (dragged).png"],
[UIImage imageNamed:#"loader-11 (dragged).png"],
[UIImage imageNamed:#"loader-12 (dragged).png"],
[UIImage imageNamed:#"loader-13 (dragged).png"],
[UIImage imageNamed:#"loader-14 (dragged).png"],
[UIImage imageNamed:#"loader-15 (dragged).png"],
[UIImage imageNamed:#"loader-16 (dragged).png"],
[UIImage imageNamed:#"loader-17 (dragged).png"],
[UIImage imageNamed:#"loader-18 (dragged).png"],
[UIImage imageNamed:#"loader-19 (dragged).png"],
[UIImage imageNamed:#"loader-20 (dragged).png"],
[UIImage imageNamed:#"loader-21 (dragged).png"],
[UIImage imageNamed:#"loader-22 (dragged).png"],
[UIImage imageNamed:#"loader-23 (dragged).png"],
[UIImage imageNamed:#"loader-24 (dragged).png"],
[UIImage imageNamed:#"loader-25 (dragged).png"],
[UIImage imageNamed:#"loader-26 (dragged).png"],
[UIImage imageNamed:#"loader-27 (dragged).png"],
[UIImage imageNamed:#"loader-28 (dragged).png"],
[UIImage imageNamed:#"loader-29 (dragged).png"],
[UIImage imageNamed:#"loader-30 (dragged).png"], nil];
animatedImageView.animationDuration = 0.55f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[placeholderView addSubview:animatedImageView];
[self.view insertSubview:placeholderView belowSubview:_tweetTable];
self.placeholderView = placeholderView;
_tweetTable.alpha = 0.0f;
}
Turns out my frame rate was too high (60 fps) which made the iPhone do too much work. Reducing the duration to 1.0f at 30 frames, decreased the frames per second to 30 fps which solved my issue.
I am trying to create a gif as a place holder for my SDImageCache.
So first off I created the gif:
_imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.thumbnailImageView.frame.size.width,
cell.thumbnailImageView.frame.size.height)];
_imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00001"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00002"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00003"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00004"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00005"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00006"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00007"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00008"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00009"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00010"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00011"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00012"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00013"], [UIImage imageNamed:#"Polygon 1 copy.bolt_00014.png"], nil];
_imageView.animationRepeatCount = 500;
I then turned it into an UIimage
UIImage *imagety = _imageView.image; // get the UIImage
UIImage *otherImage = [UIImage imageNamed:#"Loadimage.png"]; // load another image
_imageView.image = otherImage; // change in the image in your UIImageView
following that I put it as the placeholder:
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache queryDiskCacheForKey:encodedString done:^(UIImage *image, SDImageCacheType cacheType) {
if (image){
cell.thumbnailImageView.image = image;
}else{
[cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:encodedString] placeholderImage:imagety completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imageCache storeImage:image forKey:encodedString];
}];
}
}];
But this does not seem to work? Do you have any ideas why?
If you check the value returned by _imageView.image:
UIImage *imagety = _imageView.image;
you should see that it is nil. This is due to your using animationImages to handle an animation through the view.
You cannot have a UIImageView (or the animation associated to it) used as a placeholder image in SDImage.
You could use:
UIImage *imagety = [UIImage animatedImageWithImages:
[NSArray arrayWithObjects:
[UIImage imageNamed:...],
nil]
duration:10.0f];
(docs)
animatedImageWithImages:duration:
Creates and returns an animated image from an existing set of images.
+ (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration
My code used to work perfectly when I used to just have an animation. However, now I tried to add sound to the animation also, I've implemented the sound as well as I can however now every time the app runs it shuts down and gives me the SIGABRT error, here is my code:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
}
- (IBAction)Button {
AudioServicesPlaySystemSound(SoundID);
}
-(IBAction)startanimating{
animatedimage.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"ALambo1.jpg"],
[UIImage imageNamed:#"ALambo2.jpg"],
[UIImage imageNamed:#"ALambo3.jpg"],
[UIImage imageNamed:#"ALambo4.jpg"],
[UIImage imageNamed:#"ALambo5.jpg"],
[UIImage imageNamed:#"ALambo6.jpg"],
[UIImage imageNamed:#"ALambo7.jpg"],
[UIImage imageNamed:#"ALambo8.jpg"],
[UIImage imageNamed:#"ALambo9.jpg"],
[UIImage imageNamed:#"ALambo10.jpg"],
[UIImage imageNamed:#"ALambo11.jpg"],
[UIImage imageNamed:#"ALambo12.jpg"],
[UIImage imageNamed:#"ALambo13.jpg"],
[UIImage imageNamed:#"ALambo14.jpg"],
[UIImage imageNamed:#"ALambo15.jpg"],
[UIImage imageNamed:#"ALambo16.jpg"],
[UIImage imageNamed:#"ALambo17.jpg"],
[UIImage imageNamed:#"ALambo18.jpg"],
[UIImage imageNamed:#"ALambo19.jpg"],
[UIImage imageNamed:#"ALambo20.jpg"],
[UIImage imageNamed:#"ALambo22.jpg"],
[UIImage imageNamed:#"ALambo23.jpg"],
[UIImage imageNamed:#"ALambo24.jpg"],
[UIImage imageNamed:#"ALambo25.jpg"],
[UIImage imageNamed:#"ALambo26.jpg"],
[UIImage imageNamed:#"ALambo52.jpg"],
[UIImage imageNamed:#"ALambo51.jpg"],
[UIImage imageNamed:#"ALambo50.jpg"],
[UIImage imageNamed:#"ALambo49.jpg"],
[UIImage imageNamed:#"ALambo48.jpg"],
[UIImage imageNamed:#"ALambo47.jpg"],
[UIImage imageNamed:#"ALambo46.jpg"],
[UIImage imageNamed:#"ALambo45.jpg"],
[UIImage imageNamed:#"ALambo44.jpg"],
[UIImage imageNamed:#"ALambo43.jpg"],
[UIImage imageNamed:#"ALambo42.jpg"],
[UIImage imageNamed:#"ALambo41.jpg"],
[UIImage imageNamed:#"ALambo40.jpg"],
[UIImage imageNamed:#"ALambo39.jpg"],
[UIImage imageNamed:#"ALambo38.jpg"],
[UIImage imageNamed:#"ALambo37.jpg"],
[UIImage imageNamed:#"ALambo36.jpg"],
[UIImage imageNamed:#"ALambo35.jpg"],
[UIImage imageNamed:#"ALambo34.jpg"],
[UIImage imageNamed:#"ALambo33.jpg"],
[UIImage imageNamed:#"ALambo32.jpg"],
[UIImage imageNamed:#"ALambo31.jpg"],
[UIImage imageNamed:#"ALambo30.jpg"],
[UIImage imageNamed:#"ALambo29.jpg"],
[UIImage imageNamed:#"ALambo28.jpg"], nil];
[animatedimage setAnimationRepeatCount:1];
animatedimage.animationDuration = 1.2;
[animatedimage startAnimating];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *buttonURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"SoundRev" ofType:#"m4a"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
Here is the (.h) also:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#interface ViewController : UIViewController
{
IBOutlet UIImageView *animatedimage;
SystemSoundID SoundID;
}
-(IBAction)startanimating;
#end
I haven't used AudioServicesCreateSystemSoundID in quite a while. I suggest switching your code to use AVAudioPlayer instead. That API is both more flexible and easier to use.
is it possible to manage multiple NSArrays on a different View Controller?
Here's my example:
I am currently working with two View Controllers:
TableViewController serves as a main menu. I've set up multiple UIButtons, each has a tag and when the user presses a button, it'll take them to the TableOneViewController.
In TableOneViewController, so far I've set up an UIImageView and a UIButton, every time the user presses the button, the UIImageView changes the image through an NSArray.
I want to use the tags on the TableViewController to manage the NSArrays of the TableOneViewController. Is this possible? So far, my code is not working.
Here's the code. Thanks!
TableViewController.m
- (IBAction)tableSelection:(id)sender
{
TableOneViewController *TOVC = [self.storyboard instantiateViewControllerWithIdentifier:#"TableOneViewController"];
if ([sender tag] == 1) {
[[NSUserDefaults standardUserDefaults] setObject:TOVC.numOne forKey:#"num"];
[[NSUserDefaults standardUserDefaults] setObject:#"1.png" forKey:#"num2"];
}
if ([sender tag] == 2) {
[[NSUserDefaults standardUserDefaults] setObject:TOVC.numTwo forKey:#"num"];
[[NSUserDefaults standardUserDefaults] setObject:#"2.png" forKey:#"num2"];
}
if ([sender tag] == 3) {
[[NSUserDefaults standardUserDefaults] setObject:TOVC.numThree forKey:#"num"];
[[NSUserDefaults standardUserDefaults] setObject:#"3.png" forKey:#"num2"];
}
[self presentViewController:TOVC animated:YES completion:nil];
}
TableOneViewController.m
- (IBAction)nextButton:(id)sender
{
int index = tableCounter++ % [self.numOne count];
self.num.image = self.numOne[index];
}
- (void)viewDidLoad
{
self.num.image = [UIImage imageNamed:[[NSUserDefaults standardUserDefaults] objectForKey:#"num"]];
self.num2.image = [UIImage imageNamed:[[NSUserDefaults standardUserDefaults] objectForKey:#"num2"]];
[super viewDidLoad];
tableCounter = 10;
self.numOne = [NSArray arrayWithObjects:
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"7.png"],
[UIImage imageNamed:#"8.png"],
[UIImage imageNamed:#"9.png"],
[UIImage imageNamed:#"10.png"],
[UIImage imageNamed:#"1.png"],
nil];
self.numTwo = [NSArray arrayWithObjects:
[UIImage imageNamed:#"20.png"],
[UIImage imageNamed:#"30.png"],
[UIImage imageNamed:#"40.png"],
[UIImage imageNamed:#"50.png"],
[UIImage imageNamed:#"60.png"],
[UIImage imageNamed:#"70.png"],
[UIImage imageNamed:#"80.png"],
[UIImage imageNamed:#"90.png"],
[UIImage imageNamed:#"100.png"],
[UIImage imageNamed:#"10.png"],
nil];
self.numThree = [NSArray arrayWithObjects:
[UIImage imageNamed:#"200.png"],
[UIImage imageNamed:#"300.png"],
[UIImage imageNamed:#"400.png"],
[UIImage imageNamed:#"500.png"],
[UIImage imageNamed:#"600.png"],
[UIImage imageNamed:#"700.png"],
[UIImage imageNamed:#"800.png"],
[UIImage imageNamed:#"900.png"],
[UIImage imageNamed:#"1000.png"],
[UIImage imageNamed:#"100.png"],
nil];
}
The problem is that you pass the array before presenting the view controller (viewDidLoad hasn't be called yet), then you present it, but you initialize numOne (and the other arrays) in viewDidLoad. I suggest to use lazy initialization, here's the example for numOne, write the same for the other two arrays:
- (NSArray*) numOne
{
if(!_numOne)
{
_numOne= [NSArray arrayWithObjects:
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"7.png"],
[UIImage imageNamed:#"8.png"],
[UIImage imageNamed:#"9.png"],
[UIImage imageNamed:#"10.png"],
[UIImage imageNamed:#"1.png"],
nil];
}
return _numOne;
}
However this is not the purpose of NSUserDefaults, I consider this approach bad design. It's better if you keep an ivar in TableOneViewController that points to one of the three arrays (same for the image name).
Edit
This is how I would implement the mechanism: an additional property that points to one of the three arrays in TableOneViewController:
#property (nonatomic, weak) NSArray* currentArray;
This pointer should point to the correct array, according to the tag of the sender that triggered tableSelection: :
// TableViewController
- (IBAction)tableSelection:(id)sender
{
TableOneViewController *TOVC = [self.storyboard instantiateViewControllerWithIdentifier:#"TableOneViewController"];
switch([sender tag]) {
case 1:
TOVC.currentArray= TOVC.numOne;
break;
case 2:
TOVC.currentArray= TOVC.numTwo;
break;
case 3:
TOVC.currentArray= TOVC.numThree;
break;
default:
return;
}
[self presentViewController:TOVC animated:YES completion:nil];
}
// TableOneViewController
- (IBAction)nextButton:(id)sender
{
int index = tableCounter++ % [self.currentArray count];
self.num.image = self.currentArray[index];
}
It doesn't work because
TableOneViewController *TOVC = [self.storyboard instantiateViewControllerWithIdentifier:#"TableOneViewController"];
creates a completely new instance of your TableOneViewController. I would use a singleton retaining the arrays and any other info I need as a single access point during the execution of my program.