search
HomeBackend DevelopmentPHP TutorialiOS development questions (4)

iOS development questions (4)

Jan 20, 2017 am 09:29 AM

32. UIImage+Scale scaling pictures
UIImage can load pictures, but we want to get a reduced or enlarged picture, which cannot be done using UIImage. Next, we add a UIImage classification to implement UIImage. Picture zoom in and out.
First, create a UIImage+Scale class.
Then, implement the method of this class:

#import <UIKit/UIKit.h>
@interface UIImage (scale)
-(UIImage*)scaleToSize:(CGSize)size;
@end
#import "UIImage+Scale.h"
@implementation UIImage (scale)
-(UIImage*)scaleToSize:(CGSize)size
{
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(size);
// 绘制改变大小的图片
[self drawInRect:CGRectMake(0, 0, size.width,size.height)];
// 从当前context中创建一个改变大小后的图片
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
// 返回新的改变大小后的图片
return scaledImage;
}
@end

Finally, the use of this class:

#import "UIImage+Scale.h"
[[UIImage imageNamed:”p.png”] scaleToSize:CGSizeMake(252.0f,192.0f)];

33. Coreplot: In a scatter plot, legendTitleForBarPlot will not be called
legendTitleForBarPlot is the data source method of the histogram. There is no such method in the data source delegate CPTScatterPlotDataSource of the scatter chart. The only way to customize the legend's title is to specify the plot's title attribute. If title is empty, the identifier attribute is used.

34. setHidesBackButton cannot hide the return button
Move setHidesBackButton:animated: to the viewDidAppear: method, not to the viewWillAppear: or viewDidLoad method.

35. cannot find protocol declaration NSURLConnectionDelegate
Starting from iOS5, NSURLConnectionDelegate was deprecated. In NSURLConnection.h, these methods became informal protocols. At the same time, a copy of these methods is copied into the official protocol NSURLConnectionDataDelegate. You can directly delete the declared in the class interface and implement these methods to use the informal protocol.
36. Warning "Property'ssynthesized getter follows Cocoa naming convention for returning 'owned'objects"
Among properties to be synthesized, the property name must not start with "new", such as "newFeature".
37. Implicit declaration of function 'xxx' is invalidin C99
This is a bug in Xcode. This error will be reported when the compiler sees a function definition for the first time but does not find the function prototype. The solution is to add the function prototype declaration before the function definition. Note that the function prototype declaration statement is inserted into the interface declaration of the class (.h header file), or before the class implementation statement (.m file).
38, -[UIImageresizableImageWithCapInsets:]: unrecognized selector
This method is new in iOS5. Please use the stretchableImageWithLeftCapWidth:topCapHeight: method in iOS4. Code:

if([img respondsToSelector:@selector(resizableImageWithCapInsets:)])
{//for iOS 5+
img=[srcImg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)]; 
}else{//iOS 4 compatibility
img=[srcImg stretchableImageWithLeftCapWidth:6 topCapHeight:0];
}

39. Calculate the string size of the specified font

CGSizemaximumLabelSize = CGSizeMake(250 ,MAXFLOAT);
CGSizeexpectedLabelSize = [LABEL.text sizeWithFont:[UIFontsystemFontOfSize:UILabel.font]
constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];

expectedLabelSize is the actual Size calculated based on the font, maximum size limit, and line break mode.
40. The ASIHTTPRequest clearDelegateAndCancel method causes the program to crash
ASIHTTPRequest does not hold the delegate object. When you cancel a request or release the delegate, in order to avoid calling the released delegate method, we should cancel the request. But the clearDelegateAndCancel method will cause a call deallocated object error and crash.
To avoid this, you should (for versions 1.8.1 and earlier):
Hold the ASIHTTPRequest object in the delegate;
When releasing the delegate or canceling the request, do not call clearDelegateAndCancel but use " [requestrelease],request=nil;".
41. Castof 'int' to 'CAMediaTimingFunction *' is disallowed with ARC
The following code causes the above error:

transition.timingFunction= UIViewAnimationCurveEaseInOut;

In fact, even in MRC (manual memory management), This code is also incorrect. The reason why there is no error is that UIViewAnimationCurveEaseInOut is usually 0, and it becomes nil when converted. In fact, this code should be modified to:

[animationsetTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut]];


The above is the content of iOS Development Questions (4). For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment