質問

I have Custom UIView class in one textview. Custom View class frame set only some one view controller. My thought is when text view delegate methods textviewdidbeginediting animation of textview based on the keyboard height not worked correctly. I am using following code

static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162;
- (void)textViewDidBeginEditing:(UITextView *)textView {
CGRect textFieldRect=
[self.window convertRect:textView.bounds fromView:textView];
CGRect viewRect =[self.window convertRect:self.bounds fromView:self];
//So now we have the bounds, we need to calculate the fraction between the top and bottom of the middle section for the text field's midline:
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y
- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
//Clamp this fraction so that the top section is all "0.0" and the bottom section is all "1.0".
if (heightFraction < 0.0)
{
    heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
    heightFraction = 1.0;
}

//    Now take this fraction and convert it into an amount to scroll by multiplying by the keyboard height for the current screen orientation. Notice the calls to floor so that we only scroll by whole pixel amounts.
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown)
{
    animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
    animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
//Finally, apply the animation. Note the use of setAnimationBeginsFromCurrentState: — this will allow a smooth transition to new text field if the user taps on another.

CGRect viewFrame = self.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self setFrame:viewFrame];

[UIView commitAnimations];

 }

-(void)textViewDidEndEditing:(UITextView *)textView{
CGRect viewFrame = self.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];

[self setFrame:viewFrame];
[UIView commitAnimations];
 }

and also attached my screen shots

enter image description here

enter image description here

how to solve this issue

役に立ちましたか?

解決

You and move your textView using animation ,

here is the code , you can set frame according to you

-(void)makeAnimation
{
    yourView.alpha = 0;
    CGRect optionsFrame = yourView.frame;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.5];

    CGRect optionsFrame2  = {0,0,320,266};
    yourView.frame  = optionsFrame2;
    yourView.alpha=1;
    [UIView commitAnimations];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top