UITextView scrolls to top on hiding keyboard in iOS 8 - uiscrollview

My UITextView uses attributet text.
When I call resignFirstResponder it always scrolls to the top.
This only happens on my iOS 8 Simulator. Not my iOS 7 phone.
Any idea to prevent this?

I think I found a work around to this.
First, instead of calling resignFirstResponder I'm now calling [textView setEditable:NO] to dismiss the keyboard.
There seems to be a bug when initializing UITextViews in iOS 8. Long story short, the subview (of my UITextView) UITextContainerView's minSize Y value was not being initialized to the same size as the UITextView's frame. It was set to 0 instead.
To force an initialization of that value, since it's not directly accessible, I found that calling [textView setScrollEnabled:NO] in viewDidLoad will set that Y to the same as my frame's size Y value, which fixed a lot of my scrolling issues in iOS 8.
I also had to set the scrolling back to enabled in viewDidAppear so that they'd still be scrollable.

Related

Getting mouse position in entire screen Mac OS X

I'm writing a program that needs to get the mouse position in the screen, (not just my view). I need to continuously update variables xPos and yPos. I've heard about subclassing nsview and adding mouseDidMove, but it is never called. (Yes, I set my window view to my custom view.) How can I do this?
You need to set the NSWindow which contains the view to window.acceptMouseMovedEvents = yes. Also if you're just looking for mouse position in the screen consider NSEvent.mouseLocation

Text starting at wrong position in textview in Xcode 6

There's no code involved at the moment, only storyboard or xib files as far as the textview is concerned. This is what I get when running the app on my iPhone 5s or via the simulator.
I'm using auto layout and size classes with the option any width-any height. An imageview at the top, then a label, then the textview.
Here's a picture of the screen. As you can see, it looks as if the text is starting behind the label, but the textview's y is after the label and the constraints seem all correct according to Xcode 6. It works fine on iPad.
Any idea of what I'm doing wrong?
I've found a way round it: textview should have no scrolling enabled and should be put in a scrollview instead, which will do the actual scrolling. Need to add constraints to both.

UIScrollView without AutoLayout shows horizontal scroll Indicator in iOS 6 but not in iOS 7

I spent several days trying to see the working UIScrollView horizontal scroll indicator (without AutoLayout) on iOS7 (on iPad). But without success.
Has anyone fixed such bug?
My project is simple and running iOS5 and iOS6 without troubles.
I found out, that on iOS7 height of the scroll indicator image is always zero:
UIImageView * scrollBar = [[scrollView subviews] lastObject];
if (scrollBar != nil)
{
PrintRect(#"FRAME", scrollBar.frame);
PrintRect(#"BOUNDS", scrollBar.bounds);
}
Result for iOS7:
FRAME x:0.000000 y:54.000000 w:338.000000 h:0.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:0.000000
but for iOS6:
FRAME x:0.000000 y:47.000000 w:338.000000 h:7.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:7.000000
So the height scroll bar image on iOS7 is equal to zero.
It's possible to change the height, but only for a quick time because during drugging the height becames zero again.
I was stuck on something similar. I am doing the CS193P course on iTunes and there was this scrollView exercise - Imaginarium. Basically it's just a UIImageView embedded in a UIScrollView. I was having the same problem that the scroll indicators were not being displayed (with Autolayout turned off)
I looked up the header file for UIScrollView in the documentation and there is this property in scrollView called scrollIndicatorInsets:
The distance the scroll indicators are inset from the edge of the scroll view.
#property(nonatomic) UIEdgeInsets scrollIndicatorInsets
It goes on to say that the default value is UIEdgeInsetsZero!! So I created a UIEdgeInset using UIEdgeInsetsMake (see documentation). Then in viewDidLoad I set this UIEdgeInsets to be my scrollView's scrollIndicatorInsets, after which my indicators appeared when I scrolled.
Hope this works for you too.

Floating UIView on UITableView broken in iOS6

In my app i have UIView that floats at the top of a UITableView (Visualise:Attached to the bottom of the navigation Bar), under iOS5 i was enabling it to float at the top using these lines of code in scrollViewDidScroll
// get the table and buttonView bounds
CGRect tableBounds = self.tableView.bounds;
CGRect buttonViewFrame = self.buttonView.frame;
// make sure the buttonView at the table's original x and y as the content moves
self.buttonView.frame = CGRectMake(tableBounds.origin.x,tableBounds.origin.y,buttonViewFrame.size.width,buttonViewFrame.size.height);
This however no longer seems to work in iOS6, does anyone know why or how to fix the problem? I'm supporting iOS5 and above.
Having looked through the iOS6 release notes i found this...
Note that you can make a subview of the scroll view appear to float (not scroll) over the other scrolling content by creating constraints between the view and a view outside the scroll view’s subtree, such as the scroll view’s superview.
How would I set this up in code as Im not using AutoLayout in storyboards as I'm still supporting iOS5. It would also be great if anyone can enlighten me as to why the code i was using in iOS5 no longer works in 6.

UIPopovercontroller detached from UIButton

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

Resources