AFOpenFlow touchevent Image - iphone

does anybody know a solution that i could implement at this code,
that the pictures could be touched and an event will be started?
- (void)viewDidLoad {
[super viewDidLoad];
// loading images into the queue
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
NSString *imageName;
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
UIImage *aktuellesImage = imageView.image;
UIImage *scaledImage = [aktuellesImage scaleToSize:CGSizeMake(100.0f, 100.0f)];
[(AFOpenFlowView *)self.view setImage:scaledImage forIndex:i];
[imageName release];
[aktuellesImage release];
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];
}
I hope someone could help me and
sorry for my bad english :)

in AFOpenFlowView.m methods touchesBegan, touchMoves and touchEnded are already overriden, so just create a new delegate method for your usage and adapt these methods.

Related

Copy From One NSArray to another when generate the Randomly images from First Array

I am developing one app in which loading images from NSMutableArray. which generate the random images and load it to the UIImageview in iOS. I want to save that array after loading as it is into Another array how may I do this. Thanks in advance.
My Code As Below.
//FrontsCards is My Array
for(m=0; m<[FrontsCards count];m++)
{
ImgView.alpha=1;
ImgView.tag=m;
NSLog(#"Img View Tag %d",ImgView.tag);
randIdx=arc4random()%[FrontsCards count];
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
NSString *fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=0;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[scrollView addSubview:ImgView];
[ImgView setAccessibilityIdentifier:[FrontsCards objectAtIndex:randIdx]];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.ImgView setImage:[UIImage imageNamed:fullImageName]];
NSLog(#"full image name %#",fullImageName);
NSLog(#"Image Name = %#", fullImageName);
[self.ImgView setTag:randIdx];
[self.ImgView addGestureRecognizer:doubleTap];
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
Create Another Array and init it ViewDidLoad and add Objects one by one as they generated.
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
[yourNewArray addObject:imageName];
Try this snippet to copy an NSMutableArray
NSArray *newArray = [[oldArray mutableCopy]
OR:
NSMutableArray *newArray = [[[NSMutableArray alloc] initWithArray:oldArray copyItems:YES] autorelease];
Just after this code :
randIdx=arc4random()%[FrontsCards count];
save the index into another array and use it to point to the original array .

App getting crash in background image loading iphone

I have scroll view with 60 UIImageView's. Images displaying in these imageviews are from url and url's i get from the webservice. When user scrolls to bottom I call the webservice and get new 60 urls. After getting the url i am utilizing same UIImageView's to display images. Following is my code for displaying images.
for (UIView *viewSel in [scrlView subviews]) {
NSString *strImgUrl = [arrImgURL valueForKey:#"url"];
if ([viewSel isKindOfClass:[UIImageView class]]) {
UIImageView *imgView = (UIImageView *)viewSel;
[imgView setImage:[UIImage imageNamed:#"loading432x520.png"]];
NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:[NSString stringWithFormat:#"%#",strImgUrl]];
[arr addObject:imgView];
[self performSelectorInBackground:#selector(loadImageInBackground:) withObject:arr];
[arr release];
}
}
- (void) loadImageInBackground:(NSMutableArray *)arr {
NSLog(#"loadImage");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[arr objectAtIndex:0]]];
UIImage *img = [[UIImage alloc] initWithData:imgData];
if (img != nil) {
[arr addObject:img];
}
else{
[arr addObject:[UIImage imageNamed:#"no-image432x520.png"]];
}
[img release];
[self performSelectorOnMainThread:#selector(assignImageToImageView:) withObject:arr waitUntilDone:YES];
[pool release];
}
- (void) assignImageToImageView:(NSMutableArray *)arr{
NSLog(#"assignImage");
UIImageView *imgView = [arr objectAtIndex:1];
imgView.image = [arr objectAtIndex:2];
}
The code works perfect for first time. But when i get new urls it is working some time or getting crash. I don't know why it is getting crash. I want to stop that crash. If you are not getting to my question then let me know. Please help me for this. Thanks in advance. Valid answer will be appreciated.
Thank you all to give your help full comments to my question. I got the error. I am adding CALayer to uiimageview when allocating memory to uiimageview. I remove that CALayer code and it work perfectly. Nikita's comment help me to find my error.

OpenFlow with XML Object

Trying to use OpenFlow API for iPhone SDK.
I need the openflow to load pictures from a (image) link.
This is how it always works with local images:
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
NSString *imageName;
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
[(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
[imageName release];
NSLog(#"%d is the index",i);
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];
And I tried this:
- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index {
NSString *photoUrl = [[oldEntries objectAtIndex: 0] objectForKey: #"still"];
NSURL *photomake = [NSURL URLWithString:photoUrl];
NSLog(#"theConnection: %#",photoUrl);
NSLog(#"theConnection: %#",photomake);
AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];
// We're getting our images from the Flickr API.
getImageOperation.imageURL = photomake;
[loadImagesOperationQueue addOperation:getImageOperation];
[(AFOpenFlowView *)self.view setNumberOfImages:1];
[getImageOperation release];
}
But it just won't work. Can anyone help me?
Without knowing what 'won't work' it's hard to say, please clarify and supply the actual URL you are creating.
The only line that looks suspect is this one:
AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];
Should be:
AFGetImageOperation *getImageOperation = [[AFGetImageOperation alloc] init];
It's much easier to use:
NSURL *imageUrl = [[NSURL alloc] initWithString:[#"path/to/the/file.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
put all the images in an Array
and then you call you first function
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
[(AFOpenFlowView *)self.view setImage:**image** forIndex:i];
[imageName release];
NSLog(#"%d is the index",i);
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];

AutoResizing Image no imageView

i am using AFOpenFlow in my app, but now the Problem is,
the pictures I use are not the same size because they are from the web!
And how can i autoResizing the image at the view of the iPhone???
Here is my code from this method:
- (void)viewDidLoad {
[super viewDidLoad];
// loading images into the queue
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
NSString *imageName;
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
[(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
[imageName release];
NSLog(#"%d is the index",i);
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];
}
Thank you beforehand
Marco
scale your image before set to open flow
change your code in the loop as below:
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
UIImage *oriImage = [UIImage imageNamed:imageName];
[imageName release];
UIImage *requiredImage = [UIImage imageWithCGImage:[oriImage CGImage] scale:768/520.0 orientation:UIImageOrientationUp];
[(AFOpenFlowView *)self.view setImage:requiredImage forIndex:i];
NSLog(#"%d is the index",i);

iphone image is leaking, but where?

the image that is being displayed in this code is leaking but I cant figure out how. What I have a tableview that displays images to be displayed. Each time a user selects an image, it should remove the old image, download a new one, then add it to the scroll view. But the old image is not being released and I cant figure out why...
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[imageView removeFromSuperview];
self.imageView = nil;
NSUInteger row = [indexPath row];
NSString *tempC = [[NSString alloc]initWithFormat:#"http://www.website.com/%#_0001.jpg",[pdfNamesFinalArray objectAtIndex:row] ];
chartFileName = tempC;
pdfName = [pdfNamesFinalArray objectAtIndex:row];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *tempString = [[[NSString alloc]initWithFormat:#"%#/%#.jpg",docsPath,pdfName]autorelease];
NSData *data = [NSData dataWithContentsOfFile:tempString];
if (data != NULL){
self.imageView = nil;
[imageView removeFromSuperview];
self.imageView = nil;
UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease];
self.imageView = tempImage;
[data release];
scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .6;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .37;
}
else {
[data release];
self.imageView = nil;
[imageView removeFromSuperview];
self.imageView = nil;
activityIndicator.hidden = NO;
getChartsButton.enabled = NO;
chartListButton.enabled = NO;
saveChartButton.enabled = NO;
[NSThread detachNewThreadSelector:#selector(downloadImages) toTarget:self withObject:nil];
}
chartPanel.hidden = YES;
}
-(void) downloadImages {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
self.imageView = nil;
[imageView removeFromSuperview];
NSURL *url = [[[NSURL alloc]initWithString:chartFileName]autorelease];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease];
self.imageView = tempImage;
tempImage = nil;
scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .37;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .6;
activityIndicator.hidden = YES;
getChartsButton.enabled = YES;
chartListButton.enabled = YES;
saveChartButton.enabled = YES;
[pool drain];
[pool release];
}
This looks wrong:
self.imageView = nil;
[imageView removeFromSuperview];
You are setting imageView to nil before removing it from the superview, so the 2nd statement is really just [nil removeFromSuperview];, which isn't going to do anything.
I think the leak is what David Gelhar said, but I just wanted to add that you shouldn't access UI stuff from threads other than the main thread (so for instance, don't do [imageView removeFromSuperview] under a separate thread). This can cause very odd problems, including mysterious leaks. Try putting all that stuff in a separate method on the main thread that you call with [self performSelectorOnMainThread:] and see if it still leaks.
Also (although this wouldn't cause the leak), [pool drain] releases the autorelease pool, so you shouldn't invoke [pool release] after it--it might release the pool on the main thread, possibly causing a crash somewhere down the line (since you could over-release the pool).