Movement of UIButton which is in the UIScrollview becomes slow after pinching/zooming out - iphone

I have UIButtons in UIScrollview and also UIScrollview contains Imageview too. If i move UIButtons, particular area of the image within that UIButtons arranged will be colored..
Its happening well but my problem is movement of individual buttons are happening well If image is in normal size. and movement is getting delayed once after pinching or zooming..
Can anyone tell the reason why this is happening?
Thanks and Regards,
V.Karuna.

This kind of issue is usually down to the level of processing effort on the phone. Having to clip obscured views, and deal with transparency slows things down a lot. Make sure that you set everything you can to be opaque. This can make a massive difference. (opaque is a property of UIView therefore inherited by all controls, buttons etc)

Related

UIScrollView lags when adding UIView with multiple views

I've been working on a Crosswords app for a while and this problem keep returning no mater what i try.
The actual game runs in an UIScrollView because the player should be able to zoom, pan etc.
To the UIScrollview i have added a UIView. First i tried to add multiple UIImageViews and UILabels to the UIView but it resulted in very bad scrolling performance.
Now I've tried to create 3 subclassed UIViews where i wrote a custom drawRect method for each of them. I need 3 UIVIews because only two of the them needs to be redrawn, but not at the same time. The third one contains the clue numbers which are constant.
My UIScrollView hierarchy look like this:
UIScrollView
UIView
UIImageView (show the game board image)
UIView (shows the marked row/column)
UIView (shows the text the user writes)
UIView (shows the clue numbers)
I think the problem is that i have the UIImageView + 3 UIViews in one UIView. When I try to make this hierarchy it doesn't lag, but I'm not able to zoom, pan, scroll etc.:
UIScrollView
UIImageView (show the game board image)
UIView (shows the marked row/column)
UIView (shows the text the user writes)
UIView (shows the clue numbers)
Can you please try do guide me in the right direction. I will appreciate if I do not have to change too much, because the code in the three UIVIews are pretty long.
Thanks in advance :)
EDIT
Screenshot: http://crosswords-plus.com/puzzles/screen.png
First off, I'd recommend shrinking your UIScrollView and pulling the UIView containing the clues out of it. It sounds like it doesn't need to pan/zoom, so you're just adding to the overhead by having it contained inside the UIScrollView.
Secondly, it's hard to give much of an answer without seeing your implementation, but it seems to me that it's possible to turn the UIImageView/UIView/UIView hierarchy into 1 subclass that draws empty, blacked out or filled-in squares plus row/column numbering as necessary. That way, you only have 1 UIView in the UIScrollView and all of this is probably much simpler.
Is that helpful? Is there a reason you're using a UIImageView for the background? Is there a reason you're separating the row/column numbering from the text the user has entered?

UIScrollView lags on iPhone

I'm trying to create a crossword app. The game runs in a UIScrollView, because the player should be able to zoom, scroll etc. The largest crossword are 21x21 which means there need to be 441 touchable tiles. What i've tried so far were to create an UIView and added it as a subView to the UIScrollView. Then I call a method that creates 441 custom UIButtons and set the backgroundImage.
Some of the UIButtons need to have a custom label overlay, so i added a UILabel and set it on top of the UIButton.
When I run the app in simulator all works as it should, but when i test it on an iPhone 4 the UIScrollView lags a lot.
I don't know if this the way to do it? Can you maybe try to guide me in the right direction of how to do this so the UIScrollView won't lag on a device.
Thanks in advance.
Big UIScrollViews are difficult to make smooth without some sort of caching mechanism, such as the one provided by UITableView.
One thing you can do, however, to make life easier for your rendering, is to make sure to use opaque backgrounds whenever possible. In stead of making a view transparent you should make it the same color as its underlying view. This is something that does help.
Also, I have experienced better performance using imageWithContentsOfFile: in stead of imageNamed: for initializing images to be used in a UIScrollView.
In order to not keep all those buttons in memory, you should work with reusable table view cells, this will really improve the scroll performance. Here's one component that could make your life easier: DTGridView, there are also others (you can check Cocoa Controls)

Unable to add oversized button in UIToolbar

I have a UIToolbar in IB with a custom UIBarButtonItem that is set to an image. The image height is larger than the UIToolbar height. The image does not load for some reason. Attached is a screenshot.
You should avoid using subviews that are larger than the parent view - even if it does work and draws the view outside of the bounds, you cannot always count on it because the clipping is skipped for performance reasons and depending on the drawing order the overlapping part of the subview might be covered later. Second problem is that only the part within the frame of the superview is able to handle the touch events.
As to why you don't see your image, it's probably a different problem, I doubt it has something to do with it going outside the frame. Post your code to get more feedback ;)

Zooming out for the first time in UIScrollView is not smooth

I created UIScrollView and added UIView with lots of tiled UIButtons in the UIView. My problem is, when every time I zoom out the content using zoomToRect method of UIScrollView to the minimum scale I set, the zooming out is not smooth. But zoom-in and zoom-out for the second time is smooth. How can I make the zooming out for the first time to smooth zooming?
Thanks.
The slow initial zoom is obviously due to the phone allocating all the UIButtons the first time it has to draw them. They should be allocated incrementally or before the user starts to interact with them.
What are you doing that requires so much loading and drawing? It doesn't sound like the user would be able to interact with the million or so buttons they might be viewing.
I would suggest adding a pile of code to a UIScrollView Sub Class that makes it aware of it's content size, and it can then init the required UIButtons before the user starts to interact with your UIScrollview, or incrementally as I said.
There is demo code called 'Tiling' that sheds some light on using UIScrollViews to manage large content. It's quite complex, but a very complete demo that I'm sure most projects implement if they handle UIScrollViews with tiled content.
Before zoom out set your UIScrollView* scrollView like:
scrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);

uiview Transition problem

i have a UIview holding two other UIviews. that two subviews having 15 buttons and images. i have to translate the parent view. but the translation is not smooth in 3g phone. im using UIviewanimation and CGAffineTransformTranslate for translating the view. please help me for making it more smoother.
This is a though question to answer in a general way. I have had views that scrolled smoothly suddenly animating jerkily after just a small change. In short, you need to make sure to have as few subviews as possible and have as few non-opaque views as possible (pngs with alpha values translates to non-opaque UIImageViews).
If all else fails, you can render the whole view into an image, switch out the view for the image just before scrolling, and then re-insert the view again after the animation. That way, you are only moving one big and (hopefully) opaque view.
If you have many images make sure they are small-sized, otherwise theyd take up too much memory and there would be nothing to do. To my experience 4-5 large images(740-480) were too much for the phone to handle.