UIImage *flippedImage = [UIImage imageWithCGImage: yourImage.CGImage
scale:trimmedImage.scale
orientation:UIImageOrientationUpMirrored];
2018年2月28日 星期三
orientation 螢幕方向
// 這個是裝置的實際方向
[UIDevice currentDevice].orientation
// 這個是螢幕的方向(如果你鎖住一些方向,他就不會顯示那些方向)
[UIApplication sharedApplication].statusBarOrientation
// 旋轉螢幕時的callback
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(deviceRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
func deviceRotated(){
if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
print("Landscape")
// Resize other things
}
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
print("Portrait")
// Resize other things
}
}
[UIDevice currentDevice].orientation
// 這個是螢幕的方向(如果你鎖住一些方向,他就不會顯示那些方向)
[UIApplication sharedApplication].statusBarOrientation
// 旋轉螢幕時的callback
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(deviceRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
func deviceRotated(){
if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
print("Landscape")
// Resize other things
}
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
print("Portrait")
// Resize other things
}
}
2018年2月20日 星期二
nested preprocessor ifdef
#ifdef PRODUCTION
[buildInfoLabel setText:@""];
#else
#ifdef App_Sentry_Environment
[buildInfoLabel setText:App_Sentry_Environment];
#endif
#endif
[buildInfoLabel setText:@""];
#else
#ifdef App_Sentry_Environment
[buildInfoLabel setText:App_Sentry_Environment];
#endif
#endif
2018年2月19日 星期一
Compiler Warning messages
no rule to process file of type net.daringfireball.markdown for architecture x86_64
- Select Project Navigator
- Select your project
- Select your target
- Select Build Phases
- Move files (in this case, CHANGLELOG.md) that you don't want the compiler to process from
Compile Sources
toCopy Bundle Resources
Property access result unused - getters should not be used for side effects
self.lables.removeLastObject; 方法不要用. 要用[],不然compiler會認為是getter
[self.lables removeLastObject];
Implicit conversion from enumeration type 'SO_LOG_LEVEL' to different enumeration type 'DDLogFlag' (aka 'enum DDLogFlag')
LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, level, 0, nil, __PRETTY_FUNCTION__, message); 要先轉好型再放進去
LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, (DDLogFlag)level, 0, nil, __PRETTY_FUNCTION__, message);
Format string is not a string literal (potentially insecure)
LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, (DDLogFlag)level, 0, nil, __PRETTY_FUNCTION__, message); 參數是是用Format String不是普通String
LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, (DDLogFlag)level, 0, nil, __PRETTY_FUNCTION__, @"%@", message);
PerformSelector may cause a leak because its selector is unknown
因為可能會找不到function所以使用selector可能會有leak,這裡我們直接忽略它
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [self performSelector: aSelector]; #pragma clang diagnostic pop
warning: Consistency Error: Setting the No Action Delete Rule on EmployeeQueue.child may result in relationships to deleted objects
Fixed width constraints may cause clipping
這是Localization Issue,Xcode9擔心我們的文字輸入框在固定寛度的情況下,文字過長時會被clip掉,你可以用它推薦的解法,把trailing或leading設為>=或<=現在的寬度,也可以移除這個constrains
如果是textField你不會想在使用者輸入太長的時候延長它,你可以把width改成依container的寬度比例來work around.
2018年2月16日 星期五
版本號判斷
Starting Xcode 9, in Objective-C:
if (@available(iOS 11, *)) {
// iOS 11 (or newer) ObjC code
} else {
// iOS 10 or older code
}
Starting Xcode 7, in Swift: if #available(iOS 11, *) {
// iOS 11 (or newer) Swift code
} else {
// iOS 10 or older code
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 // iOS 11
#else
#endif
如果你是用10.3的SDK,那你就會看到下面的設定 (
在10.3SDK中的AvailabilityInternal.h
)
/* make sure a default max version is set */
#ifndef __IPHONE_OS_VERSION_MAX_ALLOWED
#define __IPHONE_OS_VERSION_MAX_ALLOWED __IPHONE_10_3
#endif
#define __IPHONE_2_0 20000
#define __IPHONE_2_1 20100
#define __IPHONE_2_2 20200
#define __IPHONE_3_0 30000
#define __IPHONE_3_1 30100
#define __IPHONE_3_2 30200
#define __IPHONE_4_0 40000
#define __IPHONE_4_1 40100
#define __IPHONE_4_2 40200
#define __IPHONE_4_3 40300
#define __IPHONE_5_0 50000
#define __IPHONE_5_1 50100
#define __IPHONE_6_0 60000
#define __IPHONE_6_1 60100
#define __IPHONE_7_0 70000
#define __IPHONE_7_1 70100
#define __IPHONE_8_0 80000
#define __IPHONE_8_1 80100
#define __IPHONE_8_2 80200
#define __IPHONE_8_3 80300
#define __IPHONE_8_4 80400
#define __IPHONE_9_0 90000
#define __IPHONE_9_1 90100
#define __IPHONE_9_2 90200
#define __IPHONE_9_3 90300
#define __IPHONE_10_0 100000
#define __IPHONE_10_1 100100
#define __IPHONE_10_2 100200
#define __IPHONE_10_3 100300
/* __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */
訂閱:
文章 (Atom)