3

In my project, I use the Facebook API "three20": https://github.com/facebook/three20/

Now, I need to customize the TTPhotoViewController. In the gallery, there's an "auto zoom". The complete width and height are always used: enter image description here

The disadvantage is that you can not see the complete photo and important information could be cut off / cropped.

How can I deactivate the automatic zoom?

Thanks!


EDIT 03-Mar-2011:

Roman's answer seems to be good, but unfortunately it doesn't helps me. Yes, the content mode UIViewContentModeScaleAspectFill is the problem:

Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

But there's no other content mode that solves my problem. I think, I have to look deep inside three20 and scale the images by myself. But I need your help to do this! So, I'll start a new "bounty" today (03/03/2011)...

Thank you very much!!


EDIT 07-Mar-2011:

Finally I got it!! roman's answer is right, I have to use UIViewContentModeScaleAspectFit.

The problem was: I use a wrong size in my Photo-Object! 320x480 worked for me:

NSMutableArray *photos = [NSMutableArray new];

for (Information *info in allImages) {
    NSString *binaryId = info.binary;

    NSString *fileName = [NSString stringWithFormat:@"documents://img/%@.jpg", binaryId];

    Photo *photo = [[[Photo alloc] initWithCaption:info.name 
                                              urlLarge:fileName 
                                              urlSmall:fileName 
                                              urlThumb:fileName 
                                              size:CGSizeMake(320, 480)] autorelease];

    [photos addObject:photo];

}

self.photoSource = [[PhotoSet alloc] initWithTitle:@"Photos" photos:photos];
Manni
  • 11,108
  • 15
  • 49
  • 67

3 Answers3

6

easiest way is to hack TTPhotoView - around line 135 (function setImage) change

self.contentMode = UIViewContentModeScaleAspectFill;

to

self.contentMode = UIViewContentModeScaleAspectFit;

sadly there does not seem to be another way currently.

roman
  • 11,143
  • 1
  • 31
  • 42
  • Thank you very much for your answer! I now have a new problem: if the image is smaller than the screen, it will no longer increased. To the image all sides remain black, the small image is in the middle. – Manni Jan 24 '11 at 20:11
  • in that case you have to hack setImage a little bit more and use a different contentMode based on the image size – roman Jan 25 '11 at 11:02
  • Roman, there's no contentMode for my purpose, so I can't use a different contentMode based on the image size. "...Fill" crops the image and "...Fit" doesn't zoom small images. There's no contentMode for the problem I described. I think I have to choose a different way and zoom (increase/decrease) the image by myself. Can you help me? – Manni Mar 02 '11 at 13:20
3

You should award your question to roman because he answers your specific question, but I want to suggest that you should consider not using three20 and implement your image scroller yourself. Take a look at Session 104, Designing Apps with Scroll Views (requires ADC login) from the WWDC 2010 session videos on iTunes. It walks you through exactly how to implement this type of interface and allows you to keep your app lean without having to add the entire three20 library to your code.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Matt Long
  • 24,438
  • 4
  • 73
  • 99
  • "You should award your question to roman" I add the bounty a lot of weeks AFTER the answer of roman, because I hoped, that a I would get a better detailed solution – Manni Mar 01 '11 at 19:09
0

Make this change in TTScrollView class

In the method

- (CGRect)frameOfPageAtIndex:(NSInteger)pageIndex 

In this method, change the following line

if (size.width > size.height) { 

to

if (size.width / size.height > self.width / self.height) { 

This worked for me.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • Thank you for your answer! Which version of three20 are you using? I can't find the line "if (size.width > size.height)" in the method "frameOfPageAtIndex". Please give me the line number in the current version: https://github.com/facebook/three20/blob/master/src/Three20UI/Sources/TTScrollView.m – Manni Mar 05 '11 at 10:19
  • Sorry didn't check the latest code. Guess the change was finally merged (wasn't there when i was using the library). This should fix the issue you are facing (did it for me at least) – lostInTransit Mar 05 '11 at 10:30
  • Unfortunately three20 behaves exactly as I described above. The entire screen is always filled and so it happened that long images gets cut off a piece. The behavior is exactly the property UIViewContentModeScaleAspectFill. Can you please check if UIViewContentModeScaleAspectFill is also in your old version? – Manni Mar 05 '11 at 10:56