Home Backend Development PHP Tutorial iOS development questions (9)

iOS development questions (9)

Jan 20, 2017 am 09:50 AM

111. Why is it useless to set layer.borderColor in IB?
I set the Runtime property of UIView in IB to obtain a rectangle effect with rounded corners and a red border, as shown in the figure below:



However, the borderColor property seems to be invalid Yes, the border cannot be displayed.
layer.borderColor is a CGColorRef property, and the color panel of the Runtime property can only get the UIColor property, so you cannot set borderColor in IB, but can only set it through code.
112. Can you still use DLog macros and ALog macros in Swift?
Complex macros used in C and Objective-C cannot be used in Swift. Complex macros are macros in addition to constant definitions, including function macros with parentheses. We can define a global function instead:

func dLog(message: String, filename: String = __FILE__, function: String =__FUNCTION__, line: Int = __LINE__) {
if DEBUG==1 { 
println("[\(filename.lastPathComponent):\(line)] \(function) -\(message)")
}
}
Copy after login

113. Enumerations in O-C cannot be used in Swift?
Error: Enum case pattern cannot match values ​​of the non-enum type 'enumeration name'
As of Beta 5, Swift can only map enumeration classes defined using the NS_ENUM macro in O-C. Therefore, all O-C enumerations defined in typedef enum mode need to be redefined with NS_NUM:

typedef enum {
ChinaMobile = 0, // MNC 00 02 07
ChinaUnicom, // MNC 01 06
ChinaTelecom, // MNC 03 04
ChinaTietong, // MNC 20
Unknown
} CarrierName;
Copy after login

114. Can the #ifdef macro not be used in Swift? #if/#else/#endif can be used in
Swift:

#if DEBUG
let a = 2
#else
let a = 3
#endif
Copy after login

But the DEBUG symbol must be defined in Other Swift Flags:



115. What is the difference between textFieldShouldReturn method returning YES or NO?
Returning YES will trigger automatic text correction and automatic first letter capitalization (the so-called default behavior in Apple documentation), returning NO will not.
116. How to change the row height of UITextView?
First set the layoutManager.delegate of UITextView:
textView.layoutManager.delegate = self; // you'll need to declare you
Then implement the delegate method:

- (CGFloat)layoutManager:(NSLayoutManager *)layoutManagerlineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndexwithProposedLineFragmentRect:(CGRect)rect
{
return 4; // 这是行间距
}
Copy after login

117. Modify the minimum height of UITextView
No matter how you modify the frame height of UITextView in IB, it is useless. UITextView's minimum height is calculated through its content, and its minimum height is equal to the height of a single row. Therefore, on iOS 7, you can modify the minimum height by setting its textContainerInset (iOS 6 is contentInset):

if (NSFoundationVersionNumber >NSFoundationVersionNumber_iOS_6_1) {
self.textContainerInset =UIEdgeInsetsMake(4, 10, 4, 10);
} else {
self.contentInset =UIEdgeInsetsMake(4, 10, 4, 10);
}
Copy after login

117. After inserting a picture (NSTextAttachment), the NSAttribtuedString font is inexplicably smaller
Font before inserting the picture:



After inserting the picture:



This is because NSTextAttachment is inserted in superscript form, which results in three Attributes modified: font, baseline, NSSuperscriptAttributeName.
So after inserting the picture, you need to change these three values ​​​​to the default (just modifying the font will not work):

[mutableAttrString addAttributes:
@{NSFontAttributeName:[UIFontsystemFontOfSize:16],(id)kCTSuperscriptAttributeName:@0,NSBaselineOffsetAttributeName:@0} range:NSMakeRange(0,mutableAttrString.length)];
Copy after login

Note that NSSuperscriptAttributeName is invalid in iOS. Therefore, you need to use CoreText's kCTSuperscriptAttributeName instead.
118. How to push two ViewControllers into the navigation controller at one time?
Just do this:

[viewController1.navigationController pushViewController:viewController2animated:NO];
[viewController2.navigationController pushViewController:viewController3animated:YES];
Copy after login

The first PUSH will not have animation, and the second PUSH will have animation Animation, so that the user will think that only one ViewController has been pushed, but in fact you have pushed two.
119. Count the number of lines of code in the entire project
Open the terminal, use the cd command to locate the directory where the project is located, and then call the following naming to count the number of lines and total number of each source code file:

find . "(" -name "*.m" -or -name "*.mm" -or-name "*.cpp" -or -name "*.h" -or -name "*.rss"")" -print | xargs wc -l
其中,-name "*.m" 就表示扩展名为.m的文件。同时要统计java文件和xml文件的命令分别是:
find . "(" -name "*.java" ")" -print | xargs wc -l
find . "(" -name "*.xml" ")" -print | xargs wc -l
Copy after login

120. How to reduce the delay of requireGestureRecognizerToFail method?
requireGestureRecognizerToFail is generally used to distinguish between single-click and double-click recognition. Suppose you have two gestures, a single click and a double click. If you don’t want it to be recognized as a single click and double click at the same time when the user double-clicks, you can use the following code:

UITapGestureRecognizer *doubleTapGestureRecognizer =[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTapGestureRecognizer];
UITapGestureRecognizer *singleTapGestureRecognizer =[[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSingleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
[singleTapGestureRecognizer requireGestureRecognizerToFail: doubleTapGestureRecognizer];
[selfaddGestureRecognizer:singleTapGestureRecognizer];
Copy after login

But this method has a fatal flaw , since each click must first be recognized as a double-click, and the double-click recognition must fail before the click is processed, resulting in a delay for each click, generally this time is 0.35 seconds. Although 0.35 seconds is short, users can feel a noticeable delay. Therefore, we need to overload TapGestureRecognizer to reduce this delay:

#import <UIKit/UIGestureRecognizerSubclass.h>
#define UISHORT_TAP_MAX_DELAY 0.25
@interface UIShortTapGestureRecognizer : UITapGestureRecognizer
@property(nonatomic,assign)float maxDelay;
@end
#import"UIShortTapGestureRecognizer.h"
@implementation UIShortTapGestureRecognizer
- (instancetype)initWithTarget:(NSObject*)target action:(SEL)selector{
self=[super initWithTarget:targetaction:selector];
if (self) {
self.maxDelay=UISHORT_TAP_MAX_DELAY;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:toucheswithEvent:event];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(self.maxDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
// 0.1 秒后,宣告手势识别失败
if (self.state !=UIGestureRecognizerStateRecognized)
{
self.state= UIGestureRecognizerStateFailed;
}
});
}
@end
Copy after login

Now you can set its maxDelay property after instantiating UIShortTapGestureRecognizer. Note that this value should not be less than 0.2 seconds (the user must be very fast, otherwise the double-click action cannot be completed), and the optimal value is 0.25.

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

Statement of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1250
24
The first version of Apple's iOS 18 was exposed to have so many bugs: serious fever, WeChat delay The first version of Apple's iOS 18 was exposed to have so many bugs: serious fever, WeChat delay Jun 13, 2024 pm 09:39 PM

The annual WWDC has ended, and iOS18 is undoubtedly the focus of everyone's attention. Currently, many iPhone users are rushing to upgrade to iOS18, but various system bugs are making people uncomfortable. Some bloggers said that you should be cautious when upgrading to iOS18 because "there are so many bugs." The blogger said that if your iPhone is your main machine, it is recommended not to upgrade to iOS18 because the first version has many bugs. He also summarized several system bugs currently encountered: 1. Switching icon style is stuck, causing the icon not to be displayed. 2. Flashlight width animation is often lost. 3. Douyin App cannot upload videos. 4. WeChat message push is delayed by about 10 seconds. 5 . Occasionally, the phone cannot be made and the screen is black. 6. Severe fever.

Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Jul 27, 2024 am 11:06 AM

Thanks to netizens Ji Yinkesi, xxx_x, fried tomatoes, Terrence, and spicy chicken drumsticks for submitting clues! According to news on July 27, Apple today re-released the iOS/iPadOS 18 Beta 4 update for developers. The internal version number was upgraded from 22A5316j to 22A5316k. It is currently unclear the difference between the two Beta 4 version updates. Registered developers can open the "Settings" app, enter the "Software Update" section, click the "Beta Update" option, and then toggle the iOS18/iPadOS18 Developer Beta settings to select the beta version. Downloading and installing the beta version requires an Apple ID associated with a developer account. Reported on July 24, iO

Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Aug 18, 2024 am 06:34 AM

Update: Saunders Tech has uploaded a tutorial to his YouTube channel (video embedded below) explaining how to install Fortnite and the Epic Games Store on an iPad outside the EU. However, not only does the process require specific beta versions of iO

Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Jul 31, 2024 pm 01:10 PM

According to news on July 31, Apple issued a press release yesterday (July 30), announcing the launch of a new open source Swift package (swift-homomorphic-encryption) for enabling homomorphic encryption in the Swift programming language. Note: Homomorphic Encryption (HE) refers to an encryption algorithm that satisfies the homomorphic operation properties of ciphertext. That is, after the data is homomorphically encrypted, specific calculations are performed on the ciphertext, and the obtained ciphertext calculation results are processed at the same time. The plaintext after state decryption is equivalent to directly performing the same calculation on the plaintext data, achieving the "invisibility" of the data. Homomorphic encryption technology can calculate encrypted data without leaking the underlying unencrypted data to the operation process.

New features of Apple's iOS 18 'Boundless Notes” app: expanded Scenes functionality, introduced grid alignment New features of Apple's iOS 18 'Boundless Notes” app: expanded Scenes functionality, introduced grid alignment Jun 02, 2024 pm 05:05 PM

According to news on June 1, technology media AppleInsider published a blog post today, stating that Apple will launch a new navigation function of "Scenes" for the "Freeform" application extension in the iOS18 system, and add new options for object alignment. Introduction to the "Wubianji" application First, let's briefly introduce the "Wubianji" application. The application will be launched in 2022 and has currently launched iOS, iPadOS, macOS15 and visionOS versions. Apple’s official introduction is as follows: “Boundless Notes” is an excellent tool for turning inspiration into reality. Sketch projects, design mood boards, or start brainstorming on a flexible canvas that supports nearly any file type. With iCloud, all your boards

Apple iOS 17.5 RC version released: allows EU iPhone users to download apps from the website Apple iOS 17.5 RC version released: allows EU iPhone users to download apps from the website May 08, 2024 am 09:30 AM

[Click here to go directly to the upgrade tutorial] According to news on May 8, Apple pushed the iOS17.5RC update (internal version number: 21F79) to iPhone users today. This update is 70 days away from the last release. How to upgrade iOS/iPadOS/watchOS/macOS development version and public beta version? To upgrade the iOS/iPadOS17 developer preview version and public beta version, you can refer to the experience shared by friends: Experience Post 1||Experience Post 2||Experience Post 3||Experience Post 4. Starting from the iOS/iPadOS 16.4 Developer Preview Beta 1, you need to register for the Apple Developer Program. After registration, open the system [Settings] [Software Update] to see the upgrade option. Please note that your iPhone or IP

Apple iOS/iPadOS 18 Developer Preview Beta 4 released: Added CarPlay wallpapers, sorted out settings options, enhanced camera control Apple iOS/iPadOS 18 Developer Preview Beta 4 released: Added CarPlay wallpapers, sorted out settings options, enhanced camera control Jul 24, 2024 am 09:54 AM

Thanks to netizens Spicy Chicken Leg Burger, Soft Media New Friends 2092483, Handwritten Past, DingHao, Xiaoxing_14, Wowotou Eat Big Kou, Feiying Q, Soft Media New Friends 2168428, Slades, Aaron212, Happy Little Hedgehog, Little Earl, Clues for the little milk cat that eats fish! [Click here to go directly to the upgrade tutorial] According to news on July 24, Apple today pushed the iOS/iPadOS18 developer preview version Beta4 update (internal version number: 22A5316j) to iPhone and iPad users. This update is 15 days after the last release. . Carplay Wallpaper Apple has added wallpapers to CarPlay, covering light and dark modes. Its wallpaper style is similar to iPhone

Haqu K2 projector brings Olympic passion and dreams within reach Haqu K2 projector brings Olympic passion and dreams within reach Jul 24, 2024 pm 01:34 PM

In the just-concluded European Cup final, did you cheer crazily for the team you supported? In the upcoming Paris Olympics, are you also looking forward to perfectly capturing the highlight moments of each event? Among them, having a high-quality viewing equipment is crucial. The Haqu K2 projector is well-deserved to be a good choice for watching games due to its high cost performance and excellent performance. It not only has high brightness and clear picture quality, but also provides an immersive viewing experience, making every exciting moment of the game feel as if it is close at hand. Are you already attracted by such a device? It will definitely allow you to enjoy the passion and dreams of the Olympic Games at home. The most intimate highlight of Haqu K2 is its 210° super angle adjustment, which makes it convenient to watch movies whether on the ceiling or on the wall.

See all articles