IOS 8 my UIScrollView doesn't scroll - ios

I have an issue on iOS8 my textview doensn't scroll correctly like it used to be on all previous versions.
My code is this one :
const BOOL scrollToBottom = (chatTextView.text.length == 0);
chatTextView.text = getStr;
NSUInteger length = chatTextView.text.length;
if (scrollToBottom)
{
chatTextView.selectedRange = NSMakeRange(length, 0);
[chatTextView scrollRangeToVisible:chatTextView.selectedRange];
Do you have an idea were the problem might come from ?
In the previous ios version the scroll was always scrolling to bottom when there was new messages in the chatbox. Now the scroll view always refresh to somewhere in the middle of the chat box. I've tried quick hack like NSMakeRange(length+1000, 0); but it doens't change anything

Related

UIView does not get refreshed after NSLayoutConstraint constant is changed

I want to change UITableView height depending upon user interaction with a button. When user clicks on the button, UITableView gets expanded and click on the same button UITableView height is decreased only to show 1st row. Following is my code
tblFaults?.setNeedsUpdateConstraints()
self.view.setNeedsUpdateConstraints()
if (currentNumber == 1)
{
currentNumber = 2
var newFrame = tblFaults?.frame
newFrame?.size.height += 67;//tried to change frame as well
tblFaults?.frame = newFrame!
faultViewHeight?.constant = 115
//faultView height is tableview height constraint
}
else
{
currentNumber = 1
var newFrame = tblFaults?.frame
newFrame?.size.height -= 67;
tblFaults?.frame = newFrame!
faultViewHeight?.constant = 48
}
tblFaults?.reloadData()
//self.view.setNeedsLayout()
//self.view.setNeedsDisplay()
I tried setNeedsDisplay, setNeedsLayout as well as layoutSubviews() after the code. But view does not get refreshed immediately after button click but gets refreshed only after next user interaction (e.g. scrollview change etc)
Try this :
faultViewHeight?.constant = 48
tblFaults.layoutIfNeeded() // you need to call this method
Thanks everyone.
Actually only constraint constant value change and tableview.reloadData() was enough. The BIG mistake I did was, I was checking the execution on simulator. I tried this on device and it worked perfectly fine. On simulator I was facing the issue even after trying self.view.layoutIfNeeded(). I still do not know why this is the behaviour on simulator and not on device. But eventually app has to run on device and its working there. :)
Thank you all.

After android text keyboard hided custom keyboard displayed twice

In my activity class i use both custom keyboard and android soft text keyboard. Android text soft keyboard resizes activity layout. If I open custom keyboard while soft keyboard is opened, the last one hides and layout expands back. But I open custom keyboard right after call
InputMethodManager imm = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, 0);
Here view is view with custom keyboard.
And I face the problem when custom keyboard draws twice:
When android soft keyboard is hidden, but layout is not expanded back yet. In that case custom keyboard appears at the top half of the screen.
After layout is expanded back. In that case custom keyboard appears on the bottom half of the screen.
What i want to do is somehow avoid two keyboards simultaneous appearance.
In activity code i use only SoftInput.StateAlwaysHidden WindowSoftInputMode. SoftInput.AdjustPan is not convenient because in that case some views can be hidden by android keyboard.
After hours of internet search the answer has been found. Pspdfkit has great post.
And with small investigation it has been rewritten on C# in Oncreate method:
private View decorView;
private int lastVisibleDecorViewHeight = 0;
decorView = Window.DecorView;
decorView.ViewTreeObserver.GlobalLayout += (sender, args) =>
{
Rect windowVisibleDisplayFrame = new Rect();
decorView.GetWindowVisibleDisplayFrame(windowVisibleDisplayFrame);
int visibleDecorViewHeight = windowVisibleDisplayFrame.Height();
if (lastVisibleDecorViewHeight != 0)
{
if (lastVisibleDecorViewHeight > visibleDecorViewHeight)
{
OnSoftKeyboardShown();
}
else if (lastVisibleDecorViewHeight < visibleDecorViewHeight)
{
OnSoftKeyboardHidden();
if (!isAndroidSoftKeyboardShown && customKeyboardRequested)
{
Keyboard.RequestCustomKeyboard(requestedCustomKeyboardType);
customKeyboardRequested = false;
}
}
}
lastVisibleDecorViewHeight = visibleDecorViewHeight;
};
Hope this will help someone with similar problems.

How to trace which image is currently seen in my Uiscrollview?

I am new to iOS.
I am working on UIScrollView based application. I have 3 images in UIScrollView.
I have 2 UIButtons which have selector method for Facebook and Twitter sharing.
I want to share image which is currently seen in UIScrollView to Facebook & Twitter.
I am stuck at extracting image at current scroll point.
After Googling I think something like UIPageController is the solution for me.
But I do not have any idea about how to implement it.
Please help me sort it out. Thank You!
I would say you have multiple options here, this is really a design question.
An easy (but also not very elegant) approach would be to fetch the current offset of the scroll view using its contentOffset property (depending on whether your scroll view scrolls horizontically or vertically, you have ease to use the x or y value of the contentOffset).
Next, you get the position values from your image views (again either myImageView.frame.origin.x or myImageView.frame.origin.y) and you can then calculate which of the image views is currently in the offset of the scroll view.
You can use a page controller (basically, you allow the user to end its scrolling on specific index).
Or when the user touches a button, you can retrieve the contentOffset of the scrollView and compare this value with the origin of the frame your images.
Assume, you created your images with these frames:
image1.frame = CGRectMake(0,0,320,250);
image2.frame = CGRectMake(0,250,320,250);
image3.frame = CGRectMake(0,500,320,250);
Now when you get the action:
-(IBAction)share:(id)sender {
CGPoint offset = self.scrollView.contentOffset;
if (offset.y < 250) {
//First image selected
}else if (offset.y > 500) {
//Third image selected
} else {
//Second image selected
}
}

How do I move FPPopover as low as I want? If I push it too low, it jumps back to the top

I'm using FPPopover to present a pop over view for my iPhone app. I'm having an issue, however, where when I present it, it will only allow me to present it so low or it will jump to the top. And this is well before it gets cut off anyway.
For example:
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
Works fine, but if I put it a 255 instead of 235 (as it's a good 40px from the bottom) it jumps back up to the top.
Does anyone have any experience with this or how I could fix it?
Also, bonus points if you can explain why the content for the popover always starts like 50px from the top, when I want it to start up higher. How can I change this also?
More code from the creation:
- (void)speedOptionsTapped:(UIBarButtonItem *)sender {
// Set the delegate in the controller that acts as the popover's view to be self so that the controls on the popover can manipulate the WPM and number of words shown
self.speedOptionsController.delegate = self;
self.speedOptionsPopover.arrowDirection = FPPopoverNoArrow;
self.speedOptionsPopover.border = NO;
self.speedOptionsPopover.contentSize = CGSizeMake(320, 190);
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
}
Try replacing this part of the code in FPPopoverController.m:
//ok, will be vertical
if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
with this code:
//ok, will be vertical
if (self.arrowDirection == FPPopoverNoArrow)
{
r.origin.x = p.x;
r.origin.y = p.y;
}
else if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
The reason you might be having this issue is that the macro FPPopoverArrowDirectionIsVertical considers a popover with no arrows as having a vertical arrow. So, the result is that is tries to best position your popover as close as possible to the view that triggered the popover.
If you replace the code as indicated above, you'll be creating a special case for popovers with no arrows and asking that the original points be respected without repositioning.

How do I remove bottom padding that appears below a TextBox in Windows Phone when tapped?

I am attempting to implement a chat view in Windows Phone 8. When a user taps my TextBox at the bottom of my View, the view shifts vertically as the keyboard appears, but an additional amount of padding appears at the bottom of the view. I have seen this happen in other apps as well.
Here is my app:
Here is an equivalent app (Whatsapp) that has clearly solved the problem.
Anyone have any ideas on how to correct this issue in a way that won't break my view? My attempts to manually modify padding when Focused/Unfocused have not been successful.
Good news! I have managed to figure out a fix for this. The below code stops the page from being moved up at all and then adds a margin to the bottom of the text box to place it above the keyboard. The value below of 417 seems to work well for me but you can change this to whatever you like. Using this method also stops other content being pushed off screen like the conversation as it will be fully scrollable while the keyboard is active.
private void TextBox_GotFocus_1(object sender, RoutedEventArgs e)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
rootFrame.RenderTransform = new CompositeTransform() { TranslateY = +0 };
TextInput2.Margin = new Thickness(12, 0, 12, 417);
}
private void TextBox_LostFocus_1(object sender, RoutedEventArgs e)
{
var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
rootFrame.RenderTransform = new CompositeTransform() { TranslateY = +0 };
TextInput2.Margin = new Thickness(12, 0, 12, 12);
}
You can always try to give bottom margin with negative value. example give -40px and see.
If you're using Grid, set Height to "Auto" where the TextBox is.
Set InputScope="Default".

Resources