uiscrollview paging skipping pages? - xcode

hi i have a uiscrollview that i have 4 images with buttons laid out vertically in storyboard, i have paging enabled but it skips most of the images and snaps onto the last one.Is there a way to make it stop on each fullscreen image without loading a bunch of uiviews?
here is the code i already have its pretty basic.
.h
IBOutlet UIScrollView *scroller2;
}
#property (nonatomic, strong) IBOutlet UIScrollView *scroller2;
#end
.m
#synthesize scroller2;
[scroller2 setContentSize:CGSizeMake(320, 3543) ];
scroller2.pagingEnabled = YES;

I dont have enough rep to post a comment so an answer will have to suffice.
I was having problems replicaing your problem so I was wondering please if you could post the size of your imageViews inside the scrollView. Also are you loading the images from the web somewhere or are they just local images?
The way paging enabled works is that it assumes that every "page" or imageview and picture in your case is right next to each other with no gaps. It calculates the pages simply by adding whatever the screen size of the device is and snapping to that next point. When you say its skipping some photos do you mean that it is snapping to halfway down a photo in some cases or just skipping right to the end?
If you try and lay everything out right underneath each other in blocks of 480px then paging enabled should work for you.
Hope this is of some help, let me know how you get on

Related

Can't change TableView size

In my.m file:
#synthesize ListLearnTab;
...........
- (void)viewDidLoad
{
[super viewDidLoad];
ListLearnTab.frame=CGRectMake(0, 0, 320, 416);
}
where ListLearnTab I declared in .h as:
#property (weak, nonatomic) IBOutlet UITableView *ListLearnTab;
I spend many hours and don't know why TableView doesn't want resize. I put this ListLearnTab.frame=CGRectMake(0, 0, 320, 416); in many places, but TableView stay as I declare in Xcode (manualy).
I had the same problem, I think. I set the size of the table in the code, like you. I could see it on the story board. The prototype cell looked correct, but only seemed to go halfway across the table when the app ran. I dragged the entire view controller out bigger on the storyboard, clicked on the view itself and dragged it out, then clicked on the table and did the same. If I recall, I changed the widths of everything in the inspector to make them larger than the frame specification in viewDidLoad.
I got everything working. Sorry about not remembering the exact step that solved the problem.
If that's the same as your trouble, how this helps! -Rob

Adding a NSButton to a CALayer in OS X Cocoa

I have a layer hosting view containing a CAlayer, displaying in this case a nice blue opaque rectangle. What I want to do is to add a NSButton on top of the layer, so that it sits above and moves with the blue rectangle when it is animated.
My attempt so far is as follows:
in #interface
IBOutlet NSButton* firstButton;
in #implementation
[layer addSublayer:[firstButton layer]];
firstButton.layer.position=NSMakePoint(0, 80.);
This successfully moves the location of the button on screen, but it doesn't move the 'hit target' of the button.
According to the similar question asked here on Apple Mailing Lists the solution seems to be to move the NSButton with a setFrameOrigin: on the button. This doesn't seem to work for me as it changes the position of the displayed button as well as the 'hit target'. I can't seem to move the hit target independently.
Alternatively: Am I going about this all the wrong way? Is there a better way of doing this?
Unfortunately you cannot move buttons (including the hit target) by manipulating their layers. This is highly unfortunate, but you're going to have to use the animator proxy on the frame of the button itself, and not try to modify the layer directly.

UIScrollView unintended content displacement in landscape mode

I' ran into an absolutely weird kind of problem I don't have a clue yet how to fix it, having been working on this without a break (except for eating, sleeping, drinking coffee and smoking) for almost two days now.
What I have:
I've got an UIScrollView inside my view controller, containing a certain number of textfields and a UICollectionView. With a button, I open another view controller for adding new data to the collection view. Back to my first view controller after the new data items have been added, I call invalidateIntrinsicContentsize on my UIScrollView and on my UICollectionView to resize them both to fit their content (I use Autolayout and let both of them hug their content). On both views I've implemented these methods to nicely fit their content, and this part works perfectly fine.
What my problem is:
If I add data to the UICollectionView in the way just described, and if I'm in landscape mode, the problems start: After getting back to my initial view controller and updating the intrinsic content sizes, the content of my UICollectionView is displaced - displaced in such a way, that the scrolling position of the content inside the UIScrollView before switching to the data-adding view now becomes something like a fixed content offset. If I scroll up now, I can reach at maximum that position of the content where it has been - by getting scrolled to - before I switched to the data-adding view controller.
Pictures (everyone loves that):
To illustrate that situation somehow difficult to explain, I appended two pictures. Red is the entire content area of the scroll view, dark green is the content, where both overlap the color is olive. The visible part of the UIScrollView is shown in the highlighted, bordered area.
Before updating the data, content is where it should be:
(source: grubbrother.com)
After updating the data and updating UI, content is displaced by former scroll position / contentOffset:
(source: grubbrother.com)
Please help me with this weird stuff. Unfortunately, I've got a tight deadline and need to move on with the project. Nevertheless I really don't know how to solve this or even what might cause it - I have absolutely no clue.
Despite I couldn't find out yet what causes the problem described in my question, I found a hack around it that at least somehow fixes the symptoms:
As I describe above, the unwanted content displacement that occurs when switching back to the UIViewController containg the buggy UIScrollView is equal to the contentOffset of the UIscrollView before switching to another scene.
Knowing this, I set the contentOffset to zero after my UIViewController disappears.
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.scrollView setContentOffset: CGPointZero];
}
When the view reappears, I scroll down to the newly added content at the bottom of the UIScrollView in question:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (self.appearedFromActorsAdding)
{
[self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.frame.size.height) animated:YES];
}
}
Hope this helps anyone running into the same problem.

How to animate a tabbarbutton image

I have a toolBarItem which calls a save action on a database. I would really much like to change the image of the item (a cabinet) dynamically so that a drawer opens, a label is animated "inside" and then it closes. Very much like the trash item on the mail app animation.
I know how to make a UIView pop-up by scaling it up and down on an animation on a given times given in an array (together with an array of CT scale), so I'm guessing it could be done more or less the same way.
Does anyone know about an example of who to accomplish that?. Back on xcode 4.1 i was able to highlight the button while the label was moving, but I cannot do that anymore (somehow I did add a normal button on the toolbarItem, which I cannot do anymore).
Thanks in advance!
well, if somebody is having the same issue here is how it can be done:
- (IBAction)barButtonAction:(UIBarButtonItem *)sender {
NSArray *frameArray=[NSArray arrayWithObjects:[UIImage imageNamed:#"01-refresh.png"], [UIImage imageNamed:#"02-redo.png"], [UIImage imageNamed:#"03-loopback.png"], [UIImage imageNamed:#"03-loopback.png"],[UIImage imageNamed:#"03-loopback.png"],[UIImage imageNamed:#"03-loopback.png"],[UIImage imageNamed:#"03-loopback.png"],[UIImage imageNamed:#"03-loopback.png"], nil];
self.button.image=[UIImage animatedImageWithImages:frameArray duration:10.0];
}

UITableView Stretching Issue

I have a UIViewController that has an image and label at the top followed by a UITableView. In the IB it looks perfect, but when I run the application in the simulator the UITableView is stretching and taking up the entire screen.
I've turned off all autosizing and set all of the values for stretching to 0, but it's still taking up the entire screen. I even tried some advice I saw on another post which suggested putting the UITableView in a UIView that was sized, but that did not work either.
Any suggestions on how to stop the UITableView from resizing and filling the screen? I am running XCode 4.2.1 with iOS5.
You can give frame size to your tableView like this-
1) make your tableView's IBOutlet property in .h class, and synthesize in .m class.
2) connect it in Xib.
3) than in your .m class place this code in viewDidLoad-
tblView.frame = CGRectMake(0.0f, 30.0f, 320.0f, 50.0f); // you can give any size to your table

Resources