Skip to content
jun 26 11

Iphone Zoom image with UIScrollView and UIImageView

by Vinícius Krolow

Hi.

To make zoom and scroll, we can use the UIScrollView, in this post I will explain how to combine the UIViewScroll with image (UIImageView, UIImage) to make a zoom image feature.

Suppose that we have a ViewController called ZoomViewController:

The interface should be:

1
2
3
4
5
6
7
8
9
10
11
12
13
#import <uikit /UIKit.h>
 
 
@interface ZoomViewController : UIViewController <uiscrollviewdelegate> {
 
	IBOutlet UIScrollView *scroll;
	UIImageView *image;
}
 
@property (nonatomic, retain) UIScrollView *scroll;
 
@end
</uiscrollviewdelegate></uikit>

In the interface of ZoomViewController we tell that the class must implement the interface of UIScrollViewDelegate.

And create two attributes one is the UIScrollView that we named *scroll and the another one is the UIImageView that we named *image.

And we set the setter and getter for the *scroll.

Let’s go implement this interface:

First we must set our UIScrollView and our UIImageView, then in the viewDidLoad method

1
2
3
4
5
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_body.png"]];
        [super viewDidLoad];
}

We create the image, and so going to interface builder and drag one UIScrollView to the interface and connect this one with our IBOutlet attribute that is the *scroll

After that we must add our image inside our UIScrollView and config the scroll so we do:

1
2
3
4
5
6
7
8
9
10
11
// Implement viewDidLoad to do additional setup after loading the v iew, typically from a nib.
- (void)viewDidLoad {
	image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_body.png"]];
	scroll.contentSize = image.frame.size;
	[scroll addSubview:image];
	scroll.minimumZoomScale = 0.4;
	scroll.maximumZoomScale = 4.0;
	scroll.delegate = self;
	[scroll setZoomScale:scroll.minimumZoomScale];
    [super viewDidLoad];
}

We set the contentSize of scroll for the same of the image original so we will have all image to show inside the scroll view, we add the image as a subview in the scroll, and set the configs of our scroll, like the minimum and maximum zoom scale and pass the delegate of the scroll as our class.

Now we must set our response of the image when have some zoom or drag the image should response so let’s implement the method:

1
2
3
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
	return image;
}

In the end we have this class, and we have our feature a image inside a UIScrollView and this image have the feature to drag and zoom.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//  ZoomViewController.m
 
#import "ZoomViewController.h"
 
 
@implementation ZoomViewController
 
@synthesize scroll;
 
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/
 
 
// Implement viewDidLoad to do additional setup after loading the v iew, typically from a nib.
- (void)viewDidLoad {
	image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_body.png"]];
	scroll.contentSize = image.frame.size;
	[scroll addSubview:image];
	scroll.minimumZoomScale = 0.4;
	scroll.maximumZoomScale = 4.0;
	scroll.delegate = self;
	[scroll setZoomScale:scroll.minimumZoomScale];
    [super viewDidLoad];
}
 
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
	return image;
}
 
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
 
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
    // Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
 
 
- (void)dealloc {
    [super dealloc];
}
 
 
@end
mar 29 11

Custom var_dump in xdebug with PHP it’s not working

by Vinícius Krolow

If the custom var_dump of xdebug, it’s not working in your PHP config, check the php.ini file and search for the html_errors, turn it off, and it’s done.

This happened at the ubuntu 10.10 with the php 5.3 version. To install the xdebug:


sudo apt-get install php5-dev php5-xdebug

mar 22 11

Pimcore: PHP CMS that you must know!

by Vinícius Krolow

Pimcore is not just another CMS, forget about Drupal, WordPress (kind of CMS), Typo3, Joomla or some others CMS. Think about a robust solution for your websites and a simple way to create types of contents, regions to be editable, to administrate files and at last but not at least with a great framework at backside the Zend Framework. I’m just delighted with the power of this CMS, a complex, powerful and great solution with a great interface and code, that becomes so simple to do the things. You have to put a simple way to your client update his site, pimcore provide this:

Working with Documents from pimcore on Vimeo.

But your client also wanna administrate some PDF files, yep no problem for pimcore:

pimcore web2print from pimcore on Vimeo.

You have to create some dynamic contents, for example a news system, ok no problem for you Pimcore will provide for you a friendly interface where you haven’t to code to create one admin interface to create the news system for your client:



see more We need one good file administration, yep they know, and they have a good one:



In the end you ask but this works well, they answer this for you too with a showcase. I’m so impress with this CMS, it’s not normal i like something as much I liked this CMS, I’d like to congrats the team of pimcore, for this so great tool.

You can check some videos in their user at vimeo: http://vimeo.com/pimcore

jan 28 11

CakePHP one form with multiple model validate, and form display errors

by Vinícius Krolow

Sometimes we have one form that uses multiples models, and we must validate this model and display the errors messages into the form, doing one normal validate, just one model per time is validate, to do both in the same time we have a simple way to do, that is using the CakePHP model method saveAll.

We must have to tell for the save all that he just has to validate. Let’s see the piece of code.

Using for examplem one model User that hasOne Profile.

1
$this->User->saveAll($this->data, array('validate' => 'only'));

With this we validate the data of model User also the data of model Profile, and in the form will show the error message of both models, this will work with more relations.

dez 17 10

Django – Model cascade, set relation models to None Null

by Vinícius Krolow

In django when you delete one object of model and this one have relation, the django apply by default the cascade action deleting all the relations of this current model that you want delete, sometimes you do not want this cascade, you just want to pass the relations model to none or null, to do it you can use the clear method:

For example having these models:

models.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Person(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100)
 
	def __unicode__(self):
		return self.name
 
class House(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100)
	person = models.ForeignKey(Person, null=True)
 
	def __unicode__(self):
		return self.name

You want to delete one Person, so when delete this Person django automatic delete the house, when you do just it:

1
2
person = Person.objects.get(pk=1)
person.delete()

To keep the house and pass the relation to null you should do it:

1
2
3
person = Person.objects.get(pk=1)
person.house_set.clear()
person.delete()

So you get the person, set to load the house of this person and clear the relation, and so you are able to delete the person, you can check that the house will still in database but without the foreign key of Person.