2013-06-26 63 views
1

我一直在尋找如何做,在iOS6的一個UIPanGestureRecognizer東西,看着頭文件UIPanGestureRecognizer.h的一部分:爲什麼iOS頭文件中列出了私人?屬性?

NS_CLASS_AVAILABLE_IOS(3_2) @interface UIPanGestureRecognizer : UIGestureRecognizer { 
    @package 
    CGPoint   _firstScreenLocation; 
    CGPoint   _lastScreenLocation; 
    NSTimeInterval _lastTouchTime; 
    id    _velocitySample; 
    id    _previousVelocitySample; 
    NSMutableArray *_touches; 
    NSUInteger  _lastTouchCount; 
    NSUInteger  _minimumNumberOfTouches; 
    NSUInteger  _maximumNumberOfTouches; 
    CGFloat   _hysteresis; 
    CGPoint   _lastUnadjustedScreenLocation; 
    unsigned int _failsPastMaxTouches:1; 
    unsigned int _canPanHorizontally:1; 
    unsigned int _canPanVertically:1; 
    unsigned int _ignoresStationaryTouches:1; 
} 

@property (nonatomic)   NSUInteger minimumNumberOfTouches; // default is 1. the minimum number of touches required to match 
@property (nonatomic)   NSUInteger maximumNumberOfTouches; // default is UINT_MAX. the maximum number of touches that can be down 

- (CGPoint)translationInView:(UIView *)view;      // translation in the coordinate system of the specified view 
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view; 

- (CGPoint)velocityInView:(UIView *)view;       // velocity of the pan in pixels/second in the coordinate system of the specified view 

@end 

我一直在尋找做一些與

CGPoint   _firstScreenLocation; 

這不是@property,所​​以它是私人的。

我的問題是:爲什麼我們能夠看到這些私人物品?鑑於它們是「私人」的,它們如何被使用?

我想也許這是在情況下,我們要繼承的對象,所以我想這樣做如下:

#import <UIKit/UIGestureRecognizerSubclass.h> 

@interface MyPanGesture : UIPanGestureRecognizer 

- (CGPoint) firstLocation; 

@end 

@implementation MyPanGesture 

- (CGPoint) firstLocation 
{ 
    return self->_firstScreenLocation; 
} 

@end 

但這構建失敗,一個鏈接錯誤:

未定義的符號對於架構armv7s: 「_OBJC_IVAR _ $ _ UIPanGestureRecognizer._firstScreenLocation」,從引用: - [MyPanGesture firstLocation]在Gesture.o LD:符號(多個)未找到架構armv7s 鐺:錯誤:連接器命令,退出代碼1失敗(使用-v看到調用)

任何人都可以幫助這個困惑的個人嗎?

+0

這些都不是私人性質。它們是實例變量,它們被標記爲「包」範圍。 – rmaddy

回答

1

看看@package。 該指令意味着只有屬於同一圖像的類可以訪問該變量;這意味着只有UIKit的類可以訪問_firstScreenLocation。

0

這正是失敗對你的狀態,這是私人的原因(實際上,這是微妙的不同,但是它是私有你)。你可以看到他們因爲是那些實例變量被暴露在它自己的的其餘部分。該包是UIKit

你不能理解它。

(旁白:公共/私人身份是獨立的是否是伊娃財產

您應該建立一個gesture recognizer delegate和而泛正在發生,將調用方法。

UIPanGestureRecognizer

Clients of this class can, in their action methods, query the UIPanGestureRecognizer object for the current translation of the gesture (translationInView:) and the velocity of the translation (velocityInView:). They can specify the view whose coordinate system should be used for the translation and velocity values. Clients may also reset the translation to a desired value.

相關問題