How to stop the keyboard "Send" button from making the keyboard hide? - keyboard

I use Objective C
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
[UIView setAnimationBeginsFromCurrentState:TRUE];
self.chat.frame = CGRectMake(self.chat.frame.origin.x, self.chat.frame.origin.y -255., self.chat.frame.size.width, self.chat.frame.size.height);
self.chit.frame = CGRectMake(self.chit.frame.origin.x, self.chit.frame.origin.y -255., self.chit.frame.size.width, self.chit.frame.size.height);
self.button.frame = CGRectMake(self.button.frame.origin.x, self.button.frame.origin.y -255., self.button.frame.size.width, self.button.frame.size.height);
[UIView commitAnimations];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
[UIView setAnimationBeginsFromCurrentState:TRUE];
self.chat.frame = CGRectMake(self.chat.frame.origin.x, self.chat.frame.origin.y +255., self.chat.frame.size.width, self.chat.frame.size.height);
self.chit.frame = CGRectMake(self.chit.frame.origin.x, self.chit.frame.origin.y +255., self.chit.frame.size.width, self.chit.frame.size.height);
self.button.frame = CGRectMake(self.button.frame.origin.x, self.button.frame.origin.y +255., self.button.frame.size.width, self.button.frame.size.height);
[UIView commitAnimations];
}
This code lets the Keyboard pop up along with the UITextField every time I click on the UITextField. I also used ResignFirstResponder.
However, on my keyboard is a SEND button. When I click on the SEND button, the Keyboard goes back down. How do I make the SEND button stop hiding the keyboard?

Related

How can I add a menu option to the NSTextAttachment popup menu is UITextView?

I want to add another menu option to the default image attachment menu options (Copy Image, Save to Camera Roll). Note that these options are shown when you long press on an image embedded in the UITextView if the textView is not in editing mode.
I have tried adding a custom menu to the uimenucontroller and using -(void)canPerformAction to enable or disable the option, however this seems to add the menu item to the uitextView's edit menu and has no affect on the attachments popup menu.
-(void)canPerformAction never seems to get called when long pressing on the image attachment.
Well according to Apple there is no public API for doing this, however as it turns out its relatively straight forward to replace the default menu with one that looks and behaves the same.
In the viewController that contains the UITextView add the following or similar and set it up as the textView's delegate.
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange {
// save in ivar so we can access once action sheet option is selected
_attachment = textAttachment;
[self attachmentActionSheet:(UITextView *)textView range:characterRange];
return NO;
}
- (void)attachmentActionSheet:(UITextView *)textView range:(NSRange)range {
// get the rect for the selected attachment (if its a big image with top not visible the action sheet
// will be positioned above the top limit of the UITextView
// Need to add code to adjust for this.
CGRect attachmentRect = [self frameOfTextRange:range inTextView:textView];
_attachmentMenuSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Copy Image", #"Save to Camera Roll", #"Open in Viewer", nil];
// Show the sheet
[_attachmentMenuSheet showFromRect:attachmentRect inView:textView animated:YES];
}
- (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView {
CGRect rect = [textView.layoutManager boundingRectForGlyphRange:range inTextContainer:textView.textContainer];
// Now convert to textView coordinates
CGRect rectRange = [textView convertRect:rect fromView:textView.textInputView];
// Now convert to contentView coordinates
CGRect rectRangeSuper = [self.contentView convertRect:rectRange fromView:textView];
// Get the textView frame
CGRect rectView = textView.frame;
// Find the intersection of the two (in the same coordinate space)
CGRect rectIntersect = CGRectIntersection(rectRangeSuper, rectView);
// If no intersection then that's weird !!
if (CGRectIsNull(rectIntersect)) {
return rectRange;
}
// Now convert the intersection rect back to textView coordinates
CGRect rectRangeInt = [textView convertRect:rectIntersect fromView:self.contentView];
return rectRangeInt;
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (actionSheet == _attachmentMenuSheet) {
switch (buttonIndex) {
case 0:
[self copyImageToPasteBoard:[_attachment image]];
break;
case 1:
[self saveToCameraRoll:[_attachment image]];
break;
case 2:
[self browseImage:[_attachment image]];
break;
default:
break;
}
}
}
- (void)saveToCameraRoll:(UIImage*)image {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
- (void)copyImageToPasteBoard:(UIImage*)image {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = UIImagePNGRepresentation(image);
[pasteboard setData:data forPasteboardType:#"public.png"];
}
-(void)browseImage:(UIImage*)image
{
OSImageViewController *_imageViewerController = [[OSImageViewController alloc] init];
UIImage *img = [[UIImage alloc] initWithData:UIImagePNGRepresentation(image)];
_imageViewerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
_imageViewerController.modalPresentationStyle = UIModalPresentationFullScreen;
_imageViewerController.delegate = self;
[self presentViewController:_imageViewerController animated:YES completion:^(void){
[_imageViewerController setImage:img];
}];
}

Textfield in cocos2d/kobold2d not showing color

I need to create a textfield where a player in my game can enter their name for highscore purposes. I followed this question: UITextField Example in Cocos2d , and successfuly created a textfield with the keyboard. However, the textfield's text is white and the background color is also white so I cannot see the textfield, only the keyboard.
Here is the code:
appdelegate.h
#import "KKAppDelegate.h"
#interface AppDelegate : KKAppDelegate
{
UITextField *nameTextField;
}
-(void)specifyPlayerName;
#end
appdelegate.m
#implementation AppDelegate
-(void) initializationComplete
{
#ifdef KK_ARC_ENABLED
CCLOG(#"ARC is enabled");
#else
CCLOG(#"ARC is either not available or not enabled");
#endif
}
- (void)specifyPlayerName
{
NSLog(#"called");
nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(60, 165, 200, 90)];
[nameTextField setDelegate:self];
[nameTextField setText:#""];
[nameTextField setTextColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
[nameTextField becomeFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
//Terminate editing
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField*)textField {
if (textField==nameTextField) {
[nameTextField endEditing:YES];
// here is where you should do something with the data they entered
GameData* data = [GameData sharedData];
data.playerName = nameTextField.text;
NSLog(#"entered: %#", data.playerName);
}
}
The method is being called from another class/button
[[[UIApplication sharedApplication] delegate]performSelector:#selector(specifyPlayerName)];
I tried to set the color of the textfield, but it is still showing up as all white. Any help would be appreciated.
I found out that the textfield was hidden behind the other view, so
[[[CCDirector sharedDirector] openGLView] addSubview:nameTextField];
instead of
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
The textfield colors are default to be black on white.

textFieldShouldReturn is not working in ipad

I am creating an application on IPad. I use a text field with default return key to write message.After writing a message I press return key..Then the keyboard dissappeared, but the method - (BOOL)textFieldShouldReturn:(UITextField *)textField {} does NOT get called. I have some code within the textFieldShouldReturn function...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
if(cPageNavType == CUTSOM_NAV_BAR){
mToolbar.frame = CGRectMake(0, 438, 320, 44);
mTableView.frame = CGRectMake(0, 40, 340, 400);
}else {
mTableView.frame = CGRectMake(0, 0, 340, 480-44-18-28);
mToolbar.frame = CGRectMake(0, 480-44-18-28, 320, 44);
}
[UIView commitAnimations];
//[self postMessage:nil];
return YES;
}
so what can I do? Thanks in advance
Things to check
Add <UITextFieldDelegate> ,make your class receiver of delegate
OfCourse add delegate method(put break points)
Connect the textfield outlets (delegates and referencing outlets if any)

performSelectorOnMainThread is not waiting to finish

I have a thread which performs some tasks.
At the end I want to run a selector to hide an image with animation.
[self performSelectorOnMainThread:#selector(finishUpdate) withObject:nil waitUntilDone:YES];
I am setting the duration to 10 seconds:
- (void) finishUpdate {
UIImageView *myImage = (UIImageView *)[self.view viewWithTag:788];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:10.0f];
myImage.frame = CGRectMake(0, 200, 320, 80);
myImage.alpha = 0.0f;
[UIView commitAnimations];
}
But it is disappearing instantly and the thread continues immediately.
Do you know how to make my thread to wait or how to display this simple animation?
It is normal behavior for the method to return immediately. [UIView commitAnimations] does not wait for the animation to finish (or any other method you use).
Kristopher Johnson is right that you shouldn't use UIGraphicsGetCurrentContext in this context. It is used in drawRect: or whenever there is a valid graphics context.
The animation context does not relate to a graphics context. Just pass NULL if you don't need any context in some animation delegate.
Instead of waiting for the selector to finish, I used sleepForTimeInterval: method to pause my thread, using the same duration as my animation.
[NSThread sleepForTimeInterval:0.3];

UIImageView scale from center using Animation Blocks

I am using the following to scale image up but it's scaling from it's left top point, how can I make the scale from center
[UIView animateWithDuration:duration delay:delay options:options
animations:^{
myImageView.frame = frame;
myImageView.alpha = alpha;
}
completion:^(BOOL finished) {
}
];
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
myImageView.transform=CGAffineTransformMakeScale(1.2, 1.2);
}
completion:^(BOOL finished){
myImageView.transform=CGAffineTransformIdentity;
}];
this will work perfectly
Good Luck
Try this:
[UIView animateWithDuration:2
animations:^{
float zoomScal = 5; //want 5x zoom
CGPoint CenterPoint = CGPointMake(200, 300); // want center point to this
imgArtifactImage.frame = CGRectMake(- CenterPoint.x * (zoomScal-1),- CenterPoint.y * (zoomScal-1),self.view.frame.size.width * zoomScal,self.view.frame.size.height * zoomScal);
} completion:^(BOOL finished){}];
It's working for me.
this can be the block of animation for the scale up the image
here as theView U Can Use the uiimageview
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:GROW_ANIMATION_DURATION_SECONDS];
theView.transform = CGAffineTransformMakeScale(1.2, 1.2);
[UIView commitAnimations];

Resources