I have a similar problem as this post
I have a scrollview where more data is visible to the user if the user scrolls to the left or scrolls to the bottom. But I am unable to find a way to tell the user that more content is available on scroll. It is not intuitive and only by experimenting, the user will find out about the scroll option.
Is there any way I can show/tell the user that scrolling is available.
Using [scrollView flashScrollIndicators] is not exactly useful as it just flashes the indicators and it is so quick that the user would surely fail to see it.
It would be great if someone can help me with this.
This is the way I did it...
I put an image on my scroll view ( for example an arrow pointing left). So using the function mentioned below, whenever the user loads the view, the image would show (telling that more content is there in the right). When the user comes to the right most of the scrollview, the image would disappear and when he scrolls again to the left, it would reappear...
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
if (scrollView1.contentOffset.x == scrollView1.contentSize.width - scrollView1.frame.size.width)
{
// reached the bottom
NSLog(#"reached right");
self.imageView.hidden = YES;
}
else
{
self.imageView.hidden = NO;
}
}
i not sure but may be u can set a timer to flash indicators so that it stays there.......
Related
I'm building an iOS 8 app that makes use of the new hidesBarsOnSwipe property on UINavgitationController to hide the nav bar while scrolling. At the same time that the nav bar hides, I'm also programmatically hiding the tab bar. On top of the tab bar, there is a text field which lets users comment on a post (much like Facebook). When the tab bar is hidden (by moving it downward and off the screen), the text field is moved down as well, so that it now sits at the bottom of the screen and so that there's no gap between the bottom of the screen and the text field.
So, things look great. But, turns out that the text field doesn't respond to touch events when it moves to the bottom of the screen. I did some digging and it appears that the reason is because the text field is outside of its superview (the view controller's view), and so touch events will not be sent to the text field.
So I think I've figured out why the issue is occurring, but I haven't yet figured out how to fix it. I've tried messing with hitTest:withEvent: and pointInside:withEvent: but didn't have any luck. Anyone have any solutions?
EDIT: Here is some code to make the question clearer (hopefully). When the nav controller's barHideOnSwipeGestureRecognizer is called, I am running the following code:
- (void)barHideSwipeGestureActivated:(UIPanGestureRecognizer*)gesture
{
[self animateTabBarUpOrDown:self.navigationController.navigationBar.frame.origin.y >= 0 completion:nil];
}
The method above is the following:
- (void)animateTabBarUpOrDown:(BOOL)up completion:(void (^)(void))completionBlock
{
if(!self.animatingTabBar && self.tabbarIsUp != up)
{
self.animatingTabBar = YES;
//to animate the tabbar up, reset the comments bottom constraint to 0 and set the tab bar frame to it's original place
//to animate the tabbar down, move its frame down by its height. set comments bottom constraint to the negative value of that height.
[UIView animateWithDuration:kTabBarAnimationDuration animations:^{
UITabBar *tabBar = self.tabBarController.tabBar;
if(up)
{
tabBar.frame = CGRectMake(tabBar.frame.origin.x, tabBar.frame.origin.y - tabBar.frame.size.height, tabBar.frame.size.width, tabBar.frame.size.height);
self.addCommentViewToBottomConstraint.constant = 0.0f;
}
else
{
tabBar.frame = CGRectMake(tabBar.frame.origin.x, tabBar.frame.origin.y + tabBar.frame.size.height, tabBar.frame.size.width, tabBar.frame.size.height);
self.addCommentViewToBottomConstraint.constant = -tabBar.frame.size.height;
}
} completion:^(BOOL finished) {
self.tabbarIsUp = up;
self.animatingTabBar = NO;
if(completionBlock)
{
completionBlock();
}
}];
}
}
Ok, finally found a solution for this one. I haphazardly messed around with changing the bounds of my view controller's view, but that was too hacky and ultimately didn't accomplish what I wanted it to.
What I ended up doing was changing my view controller's edgesForExtendedLayout property to be equal to UIRectEdgeAll which basically says that the view should take up the entire screen, and extend above top bars / below bottom bars.
I had to hack around a little bit with changing auto layout constraints on my text field so that it appeared in the right place at the right time, but overall, the solution was changing edgesForExtendedLayout to be UIRectEdgeAll - this makes the view take up the entire screen, so the text field is now still in the super view even when it animates downward, thus, allowing it to still receive touch events.
we have a couple screens where there is one button with one action to take, but the rest of the screen scrolls (full of info). So I want anchor the button to the bottom of the screen. This app has a tabbar, so the button is actually anchored 49pts above the base of the screen. This works just fine until someone goes to type into a text box. At this point the button that appears anchored at the bottom of the screen is just hanging out 49pts above the keyboard.
How do I fix this?
Here are a couple screen shots of what I'm talking about.
Figured it out. Here is the code I was using incase anyone has a similar problem. Since the keyboard takes up half the screen I only moved the button and label half the distance of the toolbar.
- (void) keyboardDidShow: (NSNotification *)notif {
_lblContinueBG.center = CGPointMake(_lblContinueBG.center.x, _lblContinueBG.center.y + 25);
_btnContinue.center = CGPointMake(_btnContinue.center.x, _btnContinue.center.y + 25);
}
- (void) keyboardDidHide: (NSNotification *)notif {
_lblContinueBG.center = CGPointMake(_lblContinueBG.center.x, _lblContinueBG.center.y - 25);
_btnContinue.center = CGPointMake(_btnContinue.center.x, _btnContinue.center.y - 25);
}
This page helped out a bunch too - similar post. Creating object programmatically and changing that object's position
I'm trying to control a UIView that comes out from the side of the screen when a user swipes left or right. Since I want the view to follow the users finger I am using a pan gesture.
All of the is working okay however the code is growing as I am looking for speed of swipe and when touches end or start to get that information. The reason I am not using a slider-out navigation type of setup, is due to the fact that this view has to be part of UIWindow so it sits onto of my UITabBar, not under it.
The problem I have is stopping the view from moving past a certain point. This is the code I tried:
In the pan gesture method:
if (self.filterView.frame.origin.x <=36){
gesture.enabled = NO;
}
This works however as the code does; it disables the gesture and swiping back no longer works. I tried this as well:
if (self.filterView.frame.origin.x <=36){
return;
}
however, this means when I swipe back, nothing happens obviously as this code executes first to check the position.
if (self.filterView.frame.origin.x <=36){
self.filterView.frame = CGRectMake(37, 0, 300, 500);
return;
}
This was the closest match - however a bug is present where it resets the view - which is correct as that's what the code does. It's not very efficient and doesn't look good.
What is a better way to solve this problem? I just want self.filterView to not go bast a certain point.
You want to check if the view has passed the point, like you are doing. Then you want to manually keep it at that point.
// this checks if the view's origin along the x-axis has gone less than or equal to 36.0f
if (CGRectGetMinX(self.filterView.frame) <= 36.0f)
{
CGRect currentFrame = self.filterView.frame;
currentFrame.x = 37.0f;
self.filterView.frame = currentFrame;
return;
}
My app is showing the following:
'Sample 1' is just a view to display content. After I click up button, 'Sample 1' will scroll up and a new view 'Sample 2' will be showed from bottom, the final result is :
I think I should append the sample 2 view at the end of up button, and just adjust the frame of sample 1 and up button to show sample 2.
But I don't know the details how to implement it. Is there a easy way to implement this?
Just place your button and the 2 sample view's in the UIScrollview and set the contentsize of the scrollview to the total height of the button and the 2 sample view's.
Next, you could disable the scrolling on the UIScrollView and connect the button to a method scrolling the UIScrollView up.
Assuming you got your UIScrollView and the 'sample' view's as properties in your custom UIViewController class you could do something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
//disable scrolling
self.scrollView.scrollEnabled = NO;
}
//connect this action to you button
- (IBAction)buttonPressed:(id)sender{
//if current position is top scroll down, otherwise scroll up.
if(self.scrollView.contentOffset.y < 1){
[self.scrollView setContentOffset:CGPointMake(0, self.sample1.frame.size.height) animated:YES];
}else{
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
}
You can try the enormego (EGO). Refer to this question:
Pull to Refresh (ios)
you can implement this using scroll view. Add the views in a scroll view and when the up button is pressed just scroll to the respective position.
I've done this before and before I get say anything about it, you want to be careful because you're creating a view larger than the screen size and therefor you are technically rendering a larger than regular view all the time. Avoiding this (while not necessary) may let you unload a view from screen if you can.
That aside, have your main view appear in a UIScrollView so you can adjust the view's position.
The code may look like:
- (IBAction)upButtonPress:(id)sender
{
[UIView animateWithDuration:2.0 animations:^{
// Approximate frame origin difference
self.scrollView.contentOffset.y = self.view.frame.size.height - upButton.frame.size.height;
} completion:^(BOOL finished) {
// if necessary, do something when animation completes
}];
}
Hey everyone. I've searched the web and really haven't found a problem quite like this. My set up is as follows: I am trying to make an app where a user drags uiimageviewss on a uiview inside a uiscrollview (which can zoom in), but also drag the image to a trashcan to be deleted. When the scrollview is zoomed in, the user can still drag because I have subclassed uiimageview and overridden the touchesMoved method. I want the user to be able to drag the uiimageviews to a trashcan in the bottom right corner of the screen. What I implemented already works when the uiscrollview is normal zoom scale, but when you zoom in you cannot drag the image to the trashcan, because well, the trashcan is a subview of the controller's view itself (this was so that it wouldn't zoom with the uiview) and of course is not in the right coordinates of the screen for the uiscrollview.
I've found a view method called ConvertRect that converts a rectangle to the coordinates of whatever view you give to the method, but this doesn't seem to be working. I do a check within each mapimage(the imageview subclass) that checks the frame of the uiimageview intersects the frame of the trashcan. So I try this method before I do that check, but like I said it doesn't seem to be working.
So with all that complicatedness, let me say in a nutshell my problem. I want to drag images over to a trashcan regardless of what zoom level at uiscrollview is at. I can make the trashcan part of the uiscrollview but I need a way to make it keep in the bottom right corner and also not zoom when the uiscrollview does. Any ideas would be so greatly appreciated, thanks guys. :)
I had the exact same challenge.
In can just describe it in short:
When you start dragging the image REMOVE it from the UISCrollView and add it as a subview the the main view of your ViewController.
make sure that the image won't get lost in the process (means: someone still retaining it).
While dragging, constantly check to see if your image entered or left the boundaries of the trash can. you can do it with the method bellow:
-(void) checkForTrashCan
{
CGRect rect = [self.delegate.trashCan convertRect:self.view.frame fromView:self.view.superview];
if ([self.delegate.trashCan rectIntersectBounds:rect])
{
if (NOT self.isInTrashMode)
{
[self enterTrashMode];
}
}
else
{
if (self.isInTrashMode)
{
[self exitTrashMode];
}
}
}
When the method rectIntersectBounds is just a simple extension method for UIView class that i wrote:
-(BOOL) rectIntersectBounds : (CGRect) rect
{
return CGRectIntersectsRect(self.bounds, rect);
}
When the drag ended check if your view is inside the trash can, and act according to the result.