It may be a dumb question, but I can't find an answer to this ...
I have an UIScrollView and inside a number of UIButtons.
When I press a button, I want to know the screen location of the button. If I use button.frame it gives me the position inside UIScrollView, which is normal.
How can I find x and y relative to screen of the button pressed?
Thanks in advance.
Your objection was right- instead, use
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
from UIView, like
[button.superview convertPoint:button.frame.origin toView:nil];
Not tested, but I believe that should work. Also see iPhone - Get Position of UIView within entire UIWindow
For swift:
let pointXY:CGPoint = (button.superview?.convert(button.frame.origin, to: nil))!
print("button pointXY: \(pointXY.debugDescription)")
Related
I want the UITextView to show the last text so I did
[self.textBox scrollRangeToVisible:NSMakeRange([self.textBox.text length], 0) ];
However, I don't want the scrolling action since it will start from the very top and scroll down each time I enter in a new line of text.
How do I go about doing this?
UITextView inherits from UIScrollView, so you can call the latter's methods directly on it.
CGPoint offsetPoint = CGPointMake(0.0, textView.contentSize.height - textView.bounds.size.height);
[textView setContentOffset:offsetPoint animated:NO];
P.S. In your question you wrote UITextField, but it was clear from your description and code that you meant UITextView. I edited the question to reflect this.
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];
}
I've been searching for some time for an answer on this problem:
How can I keep the scrollbars on my UIScrollView and UIWebview visible? So that the user knows he can scroll up or down. (like in firefox or any other browser so without touching the scrollvie first)
I read on some sites that it wasn't possible, so my other question would be:
Is there a way to add a "scrollbar" to a scrollview or webview?
Thank you very much
Maybe you could use this:
flashScrollIndicators
It won't show the scrollbar all the time, but it just flashes when the view is loaded.
Edited: Other solution:
In your view didload, you make a scrollview of you webview like this:
UIScrollview *scrollview = [webview.subviews objectAtindex:0];
you have to set the delegate of the scrollview on self:
scrollview.delegate= self
in your .h file you add
When you place in your .m file you can use:
-(void)ScrollviewDidscroll:...
(I don't know if it works when you have multiple scrollviews)
Yes you can try adding a custom view ( can be image view) on top the scrollbar. You will have to monitor the contentOffset and contentSize to know where you are. Based on this information, you can position your custom scroll bars.
I'm running into a problem with a detached UIPopovercontroller and am hoping someone has seen this behavior before.
My app runs in Landscape mode and offers a number of popover elements using the presentPopoverFromRect call. Some are launched from within the top view while others are presented from a view buried deep in the display. The popovers seem to work fine if the popover is presented from the upper 2/3rds of the iPad's display however when attempting to launch a popover from the bottom 1/3 of the display the popover is displayed detached from the UIButton. The x coordinate appears to be correct, however the y coordinate of the popover tends to be in the middle or top of the iPad screen.
I've played around with presenting the popover using a fixed position by creating a CGRect object in the lower 1/3 of the display but when the iPad renders the popover it either renders the popover in the upper 2/3rd of the view or the very bottom of the screen (if I force the CGRect value to a large y value).
At this point I'm out of ideas and hoping someone on the forum has seen this or can make suggestions as to what to try.
Thanks for any and all help,
Wes
I was able to fix my issue and thought that I'd share my solution incase someone else has the same problem.
The solution was to add a call to set the popover size BEFORE calling presentPopoverFromRect.
[mySettingsPopoverController setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[mySettingsPopoverController presentPopoverFromRect:sender.frame inView:self.navigationButtonsView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Before, I wasn't setting the popover content size prior to presenting the popover. In the viewDidAppear method of the viewcontroller of the popover I was resizing the popover to size to the tableview in the popover. Apparently by not setting the popovercontentsize before presenting the popover you get undefined behavior including the possibility of having the popover detach from the element that it is suppose to be attached to.
Wes
How can I get the on-screen location of a button in a toolbar? That is getting the rectangle frame of an NSToolbarItem? The [NSToolbarItem view] method seems to always return nil whenever the toolbar item is only a simple action button and thus I couldn't use the normal NSView methods to pinpoint the toolbar button's on-screen position.
Background
I'm trying to use Matt Gemmell's MAAttachedWindow component to point to a specific toolbar button. The component requires an NSPoint object to "point" the user to a location on the screen.
Thanks in advance.
I happened to have the same kind of problem. Although I wouldn't say I solved it, I found a way that at least works for my scenario...
In my ToolbarItem action I fetch the current mouse location - it proved to be sufficient in this case. An example implementation might look like this:
- (IBAction)showOverlay:(id)sender {
NSPoint clickedPoint = [self.window mouseLocationOutsideOfEventStream];
self.overlayController = [[MyOverlayController alloc] initAtPoint:clickedPoint];
}