UICollectionView and images - objective-c

I have a UICollectionView, and it works great, but I have a doubt.
In my view I have a UICollectionViewCell and inside that I have a UIImage.
The cell is linked to a blank view controller, and inside that I have a UIScrollView (for managing the zoom) and a UIImage (the full-size image).
I wondered if there was some delegate or something that could handle the image opening process automatically (with zoom, etc.).
Now I'm handling the zoom effect with UIScrollViewDelegate delegate and method viewForZoomingInScrollView:... but the result is very poor, definitely not fluid!

There's no built in view for doing what you want, no. You're doing the right thing with a UIImageView inside UIScrollView. If it's not very fluid, then it's likely because your image is huge. The way to get around that is to load different images for different zoom levels. So as you zoom in, listen to the UIScrollViewDelegate method called scrollViewDidZoom: and change the image to better resolution as you zoom in. Or, take a look at CATiledLayer.
Note that this has nothing to do with your UICollectionView.

Related

How to zoom UIScrollview together with added UIImage

I have a background image that is added to UIScrollView with zoom enabled. I am trying to add additional UIImage's on top of the background image that zoom together with the background image?
The idea is to have a background with multiple playing cards were the user can either see the whole playing field with small playing cards or zoom in the whole background including the playing cards for better views on the playing cards.
Your UIScrollview should contain a single zoomable UIView subview. That subview should contain your background UIImageView and all of the card UIImageViews as it's own subviews (if you add the background image first, it will be layered at the back of the resulting composite view)
The containing UIView that is the immediate subview of your scrollview should be the return value to the UIScrollviewDelegate method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
You can manage your view hierarchy through a UIView's subviews property, which is an NSArray of views. They are layered in the order of the array, so the first view on the array will be at the back when the views are composited for display.
Well you could use the scrollviewdidzoom delegate method to notify you when the scroll view has been zoomed in and out.
From there you could do a number of things like present new UIImages at a specific zoom level using the scrollView.zoomScale property.
Let me know if this helps.

UIWebView redraw on rotate

I have implemented a UIWebView object into a custom UIView (TSAlertView). My UIWebView sits in the middle of the UIView, as a subview.
When I rotate the iOS device screen, the UIWebView object redraws right on top of the old one, without deleting the old one. All the other elements of this custom UIView are destroyed and redrawn when the screen is rotated.
I imagine I must have missed some sort of procedure for deallocating resources or removing the UIWebView from view. I have tried adding 'autorelease' to the declaration of the UIWebView, but to no avail. I wonder if this is a common symptom of a simple oversight I have made in the way the UIWebView is created?
This seems to be a simple case of not telling the UIWebView object it should destroy itself before it is redrawn on each rotate - but I don't know how I can go about this...
Any wisdom gratefully received.
Ideally while rotating you should not create the views again. Instead you can rearrange the frame in delegates appropriately. In your case you might be creating a UIWebView again, which should be avoided. Instead of that, you can keep it as a class level param(Declare in .h file) and adjust the frame in delegate methods for rotation. Also please note that release/autorelease wont remove your view from superview. You need to call removeFromSuperview method to achieve that.
Check this for view resizing and layout handling

How to disable touch detection on a UIImage?

I am working on an app, which actually works like MSPaint (something to draw lines, etc...).
I got a white UIView, basically where the user draws. On top of this UIView I set up a UIImage, which is gray, with a 0,4 alpha. I want this UIImage to be used as a blotting paper. The idea is to disable touch when the user put the palm of his hand on this area, so it's more comfortable to draw (multitouch is disabled, and with this "blotting paper" you won't draw something accidentally with your palm...)
Even if I bring the UIImage to the front, on top of the view, and even if I disable user interactions on this UIImage, it is still possible to draw on the UIView. , behind the UIImage (kind of strange!)
I do not understand what's happening, because, it seems that the image is transparent, and that the UIView "behind" is still active, even if she's overlaid by the UIImage?!
Any help/indication/idea would be much appreciated! Thank you :-)
Have you set the "userInteractionEnabled" property of the UIImage to "NO" ?
You may actually want to do the opposite. When you disable user interaction or touches, the view basically becomes invisible to touches and they are passed on to the next view.
In your case you do want userInteractionEnabled because you want the view to catch those touches.
You have to disable the user interaction on the UIImageView not the UIImage and it should work.
Edit:
Or you could be sneaky and just add an empty view over it. Use the same frame size so it overlaps perfectly and thats it. You'll be able to see everything you need and it's not a subview of it so there will eb no interaction and touches will get registered but won't have any effect. :P
No better ideas unless you post some of your code...
OK, so I managed to do what I wanted to! YAY!
I got 3 different classes :
StrokesViewController (UIViewController)-the view controller
StrokesView (UIView) - the view where the user draws the strokes.
BlottingPaper (UIView) - the blotting paper.
I got a XIB file "linked" to all three.
I created this new class, called "BlottingPaper", typed UIView. the .h and .m file are actually empty (I do import #import < Foundation/Foundation.h >)
User interaction is enable on BlottingPaper.
I do not use the exclusive touch on this class.
On the XIB file, I just put a view on top of StrokesView. I link it to BlottingPaper (modify the alpha as I want, blablabla...)
And that's it! When I put the palm of my hand on it, it doesn't draw anything on the area where my hand is, but I still can draw with my finger on the rest of the StrokesView!
In addition to Dancreek's response, you should be setting buvard.userInteractionEnabled = YES; so that it captures interaction.
You should also set buvard.exclusiveTouch = YES; so that buvard is the only view which will receive touch events.
When you remove buvard you should set buvard.exclusiveTouch = NO; so that other views will regain their ability to receive touches.

How does UIBarButtonItem know which UIBarStyle the UIToolBar uses?

In Xcode ui builder when one set the UIBarStyle of the UIToolBar (such as BlackTranslucent, for example), the UIToolBarItem matches the background images to it. How does the UIToolBarItem know which style it should use?
I'm trying to do a put a custom colored image on top of the regular background tile (programatically merge a given image on top of the background image). I want to the code to be generalizable enough so that it is able to handle all UIBarStyles. That means I want to know when UIToolBarItem decides which background to use and intercept it so I can compose the button image on the fly.
Without being able to see apple's implementation of UIBarbuttonItem, I posit that they do not, in fact, know what the style of their UIToolbar is. If you look closely, they have the same alpha as their toolbar, and the same overlay (indicative of a subview). Therefore, any image that is below this highlighted layer, added as a subview, should conform to the UIToolbar's style. If you want to use multiple images though (one for each barStyle), you can determine it with self.myToolbar.barStyle and plan appropriately at -viewDidLoad time. As for true image drawing, subclass UIToolbar and override -drawRect: and use [UIImage drawInRect:rect];

How do I rotate the contents of a UIWebView?

I have made a very simple web browser app using a web view. Now I need to get the app so that when the iPhone is rotated, the text of the page is rotated as well.
How do I do this?
I am very confused by the auto-resize dialog, so it is possible I have done something wrong there.
Any help would be appreciated!
I think you sholud rotate UIWebView widget, not its contents. Contents should rotate as well. To support rotating add following code to your view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Rotated widget might look different then expected. Adjust struts and springs in Interface Builder.
I think you need to give us some sample code in order to determine what goes wrong. It is as Jacek says, the only think you should need to do is to support auto rotation on the UIWebView itself. The content should be rotated automatically.
I think you are confused by device orientation and view frame.
In most cases UIViews do change with respect to the orientation change. But to clarify - it is not because of the orientation change, but the layout change.
Only UIViewControllers need to consider device orientation - UIViews do NOT. When the device orientation changes, the UIViewController captures the event from its instance methods:
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
The UIViewController then re-layout the views - leading to reframing of the UIViews. In many cases, iOS can helps you in simplifying the relayout process by setting the UIViewAutoresizeMask. For example:
myWebview.autoresizeMask = UIVIewAutoresizeMaskFlexibleHeight | UIVIewAutoresizeMaskFlexibleHeight;
implies that when webview's superview changed its bounds, the webview will change accordingly.
As a summary, UIView only takes care of its frame / bounds etc.