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)
Related
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?
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];
}];
}
I'm creating many colour variations of an image using Core Graphics. I need to create about 320 in total but gradually, the memory usage of the app keeps increasing until it crashes. From Instruments, I see that more CGImage objects are being created and stay alive. I want to release them because I store the images to the cache directory in PNG format.
I have searched through all other solutions I could find without success. Any help is appreciated. Thanks.
Here's the main part:
+(UIImage *)tintedImageFromImage:(UIImage *)sourceImage colour:(UIColor *)color intensity:(float)intensity {
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(sourceImage.size);
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake(0, 0, sourceImage.size.width, sourceImage.size.height);
// draw alpha-mask
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextDrawImage(context, rect, sourceImage.CGImage);
// draw tint color, preserving alpha values of original image
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
[color setFill];
CGContextFillRect(context, rect);
//Set the original greyscale template as the overlay of the new image
sourceImage = [self verticallyFlipImage:sourceImage];
[sourceImage drawInRect:CGRectMake(0,0, sourceImage.size.width,sourceImage.size.height) blendMode:kCGBlendModeMultiply alpha:intensity];
UIImage *colouredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
colouredImage = [self verticallyFlipImage:colouredImage];
return colouredImage;
}
this is used to flip the image:
+(UIImage *)verticallyFlipImage:(UIImage *)originalImage {
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(tempImageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, tempImageView.frame.size.height);
CGContextConcatCTM(context, flipVertical);
[tempImageView.layer renderInContext:context];
UIImage *flippedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return flippedImage;
}
Add to verticallyFlipImage the line tempImageView.image = nil; in order to make the image view release the image. This solves the problem.
I have given a webview in Sectioned UiTableViewCell like this
if(section==0)
{
static NSString *CellIdentifier=#"Cell";
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
webView = [[UIWebView alloc] initWithFrame:CGRectZero];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.tag = 1001;
webView.userInteractionEnabled = NO;
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[cell addSubview:webView];
}
webView = (UIWebView*)[cell viewWithTag:1001];
webView.delegate=self;
webView.frame=CGRectMake(0, 0, 300, 1000);
NSLog(#"current mode: %#", [[NSRunLoop currentRunLoop] currentMode]);
[webView loadHTMLString: [NSString stringWithFormat:[arrSecCount objectAtIndex:0], indexPath.section]baseURL:nil];
return cell;
}
where as the content in webview is dynamic.in
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section==0)
{
NSString *output = [webView stringByEvaluatingJavaScriptFromString:#"document.body.scrollHeight;"];
return [output floatValue]+300;
}
}
but when content in webview increases it is overiding on other section not fitting height.i have been tried many methodson search but of no use.
Help me with your suggestions
I think the UITableViewCell will get its height before the content of the WebView is even loaded...
What is suggest is that in the delegate method of the webview :
- (void)webViewDidFinishLoad:(UIWebView *)webView
you do a
[tableView reloadData];
That means you have to keep a reference to the webview and not reloading the HTMLString everytime the cell content is updated...
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];